Skip to content

Commit

Permalink
fix(matrix): identify the correct failed version when a selector reso…
Browse files Browse the repository at this point in the history
…lves to multiple versions
  • Loading branch information
bethesque committed May 19, 2022
1 parent d5f565a commit 11e7dc1
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
25 changes: 20 additions & 5 deletions lib/pact_broker/matrix/deployment_status_summary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions spec/fixtures/approvals/matrix_integration_spec.approved.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
}
20 changes: 20 additions & 0 deletions spec/lib/pact_broker/matrix/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 11e7dc1

Please sign in to comment.