diff --git a/lib/pact_broker/matrix/deployment_status_summary.rb b/lib/pact_broker/matrix/deployment_status_summary.rb index aa34ea3af..c98082ca8 100644 --- a/lib/pact_broker/matrix/deployment_status_summary.rb +++ b/lib/pact_broker/matrix/deployment_status_summary.rb @@ -192,13 +192,28 @@ def pact_not_ever_verified_by_provider(row) PactNotEverVerifiedByProvider.new(*selectors_for(row)) end - def selector_for(pacticipant_name) - resolved_selectors.find{ | s| s.pacticipant_name == pacticipant_name } || - dummy_selectors.find{ | s| s.pacticipant_name == pacticipant_name } + # Find the resolved version selector that caused the matrix row with the + # specified pacticipant name and version number to be returned in the query. + # + # @return [PactBroker::Matrix::ResolvedSelector] + def selector_for(pacticipant_name, pacticipant_version_number) + found = resolved_selectors.select{ | s| s.pacticipant_name == pacticipant_name } + + if found.size == 1 + found.first + elsif pacticipant_version_number + found.find{ |s| s.pacticipant_version_number == pacticipant_version_number } || dummy_selector_for(pacticipant_name) + else + dummy_selector_for(pacticipant_name) + end end def selectors_for(row) - [selector_for(row.consumer_name), selector_for(row.provider_name)] + [selector_for(row.consumer_name, row.consumer_version_number), selector_for(row.provider_name, row.provider_version_number)] + end + + def dummy_selector_for(pacticipant_name) + dummy_selectors.select{ | s| s.pacticipant_name == pacticipant_name } end # When the user has not specified a version of the provider (eg no 'latest' and/or 'tag', which means 'all versions') @@ -232,7 +247,7 @@ def warnings_for_missing_interactions considered_rows.select(&:success).collect do | row | begin if row.verification.interactions_missing_test_results.any? && !row.verification.all_interactions_missing_test_results? - InteractionsMissingVerifications.new(selector_for(row.consumer_name), selector_for(row.provider_name), row.verification.interactions_missing_test_results) + InteractionsMissingVerifications.new(selector_for(row.consumer_name, row.consumer_version_number), selector_for(row.provider_name, row.provider_version_number), row.verification.interactions_missing_test_results) end rescue StandardError => e logger.warn("Error determining if there were missing interaction verifications", e) diff --git a/spec/fixtures/approvals/matrix_integration_spec.approved.json b/spec/fixtures/approvals/matrix_integration_spec.approved.json index 23230649a..9d6eebf2e 100644 --- a/spec/fixtures/approvals/matrix_integration_spec.approved.json +++ b/spec/fixtures/approvals/matrix_integration_spec.approved.json @@ -187,5 +187,11 @@ "reasons": [ "PactBroker::Matrix::NoDependenciesMissing" ] + }, + "PactBroker::Matrix::Service find when an unresolved selector resolves to more than one resolved selector (ie. all tags) identifies the correct selector for a failing row": { + "deployable": false, + "reasons": [ + "PactBroker::Matrix::VerificationFailed" + ] } } diff --git a/spec/lib/pact_broker/matrix/integration_spec.rb b/spec/lib/pact_broker/matrix/integration_spec.rb index e0766e9bc..e810288fd 100644 --- a/spec/lib/pact_broker/matrix/integration_spec.rb +++ b/spec/lib/pact_broker/matrix/integration_spec.rb @@ -561,6 +561,26 @@ module Matrix expect(subject.deployment_status_summary).to be_deployable end end + + describe "when an unresolved selector resolves to more than one resolved selector (ie. all tags)" do + before do + td.publish_pact(consumer_name: "foo", provider_name: "bar", consumer_version_number: "1") + .create_verification(provider_version: "1", success: true, tag_names: ["prod"]) + .create_verification(provider_version: "2", number: "2", success: false, tag_names: ["prod"]) + end + + let(:selectors) do + [ + UnresolvedSelector.new(pacticipant_name: "foo", pacticipant_version_number: "1") + ] + end + + let(:options) { { latestby: "cvp", tag: "prod" } } + + it "identifies the correct selector for a failing row" do + expect(subject.deployment_status_summary.reasons.first.provider_selector.pacticipant_version_number).to eq "2" + end + end end end end