Skip to content

Commit

Permalink
fix(can-i-deploy): when multiple selectors are specified, do not infe…
Browse files Browse the repository at this point in the history
…r integrations unless the "latest" or "tag" are specified
  • Loading branch information
bethesque committed Jan 29, 2020
1 parent 1aef462 commit c581929
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
14 changes: 10 additions & 4 deletions lib/pact_broker/matrix/quick_row.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,19 @@ class QuickRow < Sequel::Model(Sequel.as(:latest_pact_publication_ids_for_consum
select *SELECT_ALL_COLUMN_ARGS
select *SELECT_PACTICIPANT_IDS_ARGS

def distinct_integrations selectors
def distinct_integrations selectors, infer_integrations
query = if selectors.size == 1
pacticipant_ids_matching_one_selector_optimised(selectors)
else
select_pacticipant_ids
.distinct
.matching_any_of_multiple_selectors(selectors)
if infer_integrations
select_pacticipant_ids
.distinct
.matching_any_of_multiple_selectors(selectors)
else
select_pacticipant_ids
.distinct
.matching_multiple_selectors(selectors)
end
end

query.from_self(alias: :pacticipant_ids)
Expand Down
8 changes: 3 additions & 5 deletions lib/pact_broker/matrix/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def find_ids_for_pacticipant_names params
# Return the latest matrix row (pact/verification) for each consumer_version_number/provider_version_number
def find specified_selectors, options = {}
resolved_specified_selectors = resolve_versions_and_add_ids(specified_selectors, :specified)
integrations = find_integrations_for_specified_selectors(resolved_specified_selectors)
integrations = find_integrations_for_specified_selectors(resolved_specified_selectors, infer_selectors_for_integrations?(options))
resolved_selectors = if infer_selectors_for_integrations?(options)
resolved_specified_selectors + inferred_selectors(resolved_specified_selectors, integrations, options)
else
Expand Down Expand Up @@ -84,12 +84,10 @@ def find_compatible_pacticipant_versions selectors
find(selectors, latestby: 'cvpv').select(&:success)
end

# If one pacticipant is specified, find all the integrations that involve that pacticipant
# If two or more are specified, just return the integrations that involve the specified pacticipants
def find_integrations_for_specified_selectors(resolved_specified_selectors)
def find_integrations_for_specified_selectors(resolved_specified_selectors, infer_integrations)
specified_pacticipant_names = resolved_specified_selectors.collect(&:pacticipant_name)
QuickRow
.distinct_integrations(resolved_specified_selectors)
.distinct_integrations(resolved_specified_selectors, infer_integrations)
.collect(&:to_hash)
.collect do | hash |
required = is_a_row_for_this_integration_required?(specified_pacticipant_names, hash[:consumer_name])
Expand Down
21 changes: 21 additions & 0 deletions spec/lib/pact_broker/matrix/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,27 @@ module Matrix
end
end
end

describe "when there is a consumer with two providers, and only one of them has a verification, and the consumer and the verified provider are explicitly specified" do
before do
td.create_pact_with_verification("Foo", "1", "Bar", "2")
.create_provider_version_tag("prod")
.create_pact_with_hierarchy("Foo", "1", "Wiffle")
end

let(:selectors) do
[
{ pacticipant_name: "Foo", pacticipant_version_number: "1" },
{ pacticipant_name: "Bar", tag: "prod", latest: true}
]
end

let(:options) { { latestby: "cvpv"} }

it "should allow the consumer to be deployed" do
expect(subject.deployment_status_summary).to be_deployable
end
end
end
end
end
Expand Down

0 comments on commit c581929

Please sign in to comment.