Skip to content

Commit 4288c28

Browse files
committed
fix(matrix): correctly infer selectors when multiple selectors have been specified
1 parent b5c4e39 commit 4288c28

File tree

2 files changed

+80
-1
lines changed

2 files changed

+80
-1
lines changed

lib/pact_broker/matrix/quick_row.rb

+16-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def distinct_integrations selectors
8989
else
9090
select_pacticipant_ids
9191
.distinct
92-
.matching_multiple_selectors(selectors)
92+
.matching_any_of_multiple_selectors(selectors)
9393
end
9494

9595
query.from_self(alias: :pacticipant_ids)
@@ -194,6 +194,21 @@ def matching_multiple_selectors(selectors)
194194
}
195195
end
196196

197+
def matching_any_of_multiple_selectors(selectors)
198+
query_ids = QueryIds.from_selectors(selectors)
199+
join_verifications_for(query_ids)
200+
.join_pacticipants_and_pacticipant_versions
201+
.where {
202+
Sequel.&(
203+
Sequel.|(
204+
QueryBuilder.consumer_or_consumer_version_matches(query_ids, :p),
205+
QueryBuilder.provider_or_provider_version_matches_or_pact_unverified(query_ids, :v),
206+
),
207+
QueryBuilder.either_consumer_or_provider_was_specified_in_query(query_ids, :p)
208+
)
209+
}
210+
end
211+
197212
def join_verifications_for(query_ids)
198213
left_outer_join(verifications_for(query_ids), LP_LV_JOIN, { table_alias: :v } )
199214
end

spec/lib/pact_broker/matrix/integration_spec.rb

+64
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,70 @@ module Matrix
331331
end
332332
end
333333
end
334+
335+
describe "specifying a provider which has multiple prod versions of one consumer (explicit) and a single version of another (inferred)" do
336+
before do
337+
# Foo 1 (prod) -> Bar 2 [explicit]
338+
# Foo 2 (prod) -> Bar 2 [explicit]
339+
# Foo 3 -> Bar 2 failed [explicit]
340+
# Cat 20 (prod) -> Bar ? [inferred, missing verification]
341+
# Dog 40 -> Bar 2 failed [inferred, but not in prod]
342+
343+
td.create_pact_with_verification("Foo", "1", "Bar", "2")
344+
.create_consumer_version_tag("prod")
345+
.create_consumer_version("2")
346+
.create_consumer_version_tag("prod")
347+
.create_pact
348+
.create_verification(provider_version: "2")
349+
.create_consumer_version("3")
350+
.create_pact
351+
.create_verification(provider_version: "2", success: false, comment: "not prod, doesn't matter")
352+
.create_consumer("Cat")
353+
.create_consumer_version("20")
354+
.create_consumer_version_tag("prod")
355+
.create_pact
356+
.comment("missing verification")
357+
.create_consumer("Dog")
358+
.create_consumer_version("40")
359+
.create_pact
360+
.create_verification(provider_version: "2")
361+
end
362+
363+
let(:selector_1) { { pacticipant_name: "Bar", pacticipant_version_number: "2" } }
364+
let(:selector_2) { { pacticipant_name: "Foo", tag: "prod" } }
365+
let(:selectors) { [ selector_1, selector_2 ] }
366+
367+
subject { Service.find(selectors, options) }
368+
369+
context "with inferred selectors" do
370+
let(:options) { { latest: true, tag: "prod"} }
371+
372+
it "determines the number of integrations" do
373+
expect(subject.integrations.size).to eq 3
374+
end
375+
376+
it "finds all prod versions of Foo" do
377+
expect(subject.select { |row| row.consumer_name == "Foo"}.size).to eq 2
378+
end
379+
380+
it "finds the single prod version of Cat" do
381+
expect(subject.select { |row| row.consumer_name == "Cat"}.size).to eq 1
382+
end
383+
384+
it "is not deployable because of the missing verification for Cat v20" do
385+
expect(subject.deployment_status_summary.reasons.size).to eq 1
386+
expect(subject.deployment_status_summary.reasons.first).to be_a_pact_never_verified_for_consumer "Cat"
387+
end
388+
end
389+
390+
context "without inferred selectors" do
391+
let(:options) { {} }
392+
393+
it "is deployable" do
394+
expect(subject.deployment_status_summary).to be_deployable
395+
end
396+
end
397+
end
334398
end
335399
end
336400
end

0 commit comments

Comments
 (0)