Skip to content

Commit

Permalink
fix(pacts for verification): correct logic for returning pact for mai…
Browse files Browse the repository at this point in the history
…n branch when no consumer version selectors are specified
  • Loading branch information
bethesque committed Sep 27, 2021
1 parent 8e96ab5 commit 8847e44
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
5 changes: 3 additions & 2 deletions lib/pact_broker/pacts/pacts_for_verification_repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ def default_selectors(provider)
selectors = selector_for_latest_main_version_or_overall_latest(provider)
selectors << Selector.for_currently_deployed
selectors << Selector.for_currently_supported
logger.debug("Default selectors", payload: selectors)
selectors
end

Expand All @@ -140,9 +141,9 @@ def selector_for_latest_main_version_or_overall_latest(provider)
consumers = integration_service.find_for_provider(provider).collect(&:consumer)

consumers.collect do | consumer |
if consumer.main_branch && PactBroker::Domain::Version.for_selector(PactBroker::Matrix::UnresolvedSelector.new(branch: consumer.main_branch, latest: true)).any?
if consumer.main_branch && PactBroker::Domain::Version.for_selector(PactBroker::Matrix::UnresolvedSelector.new(branch: consumer.main_branch, pacticipant_name: consumer.name, latest: true)).any?
selectors << Selector.for_main_branch.for_consumer(consumer.name)
elsif consumer.main_branch && PactBroker::Domain::Version.for_selector(PactBroker::Matrix::UnresolvedSelector.new(tag: consumer.main_branch, latest: true)).any?
elsif consumer.main_branch && PactBroker::Domain::Version.for_selector(PactBroker::Matrix::UnresolvedSelector.new(tag: consumer.main_branch, pacticipant_name: consumer.name, latest: true)).any?
selectors << Selector.latest_for_tag(consumer.main_branch).for_consumer(consumer.name)
else
selectors << Selector.overall_latest.for_consumer(consumer.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ def find_by_consumer_name_and_consumer_version_number(consumer_name, consumer_ve
subject { Repository.new.find_for_verification("Bar", consumer_version_selectors) }

context "when there are no selectors" do

let(:foo_main_branch) { nil }

let(:consumer_version_selectors) { Selectors.new }

context "when there is no main branch version" do
before do
td.create_consumer("Foo")
td.create_consumer("Foo", main_branch: "main")
.create_pact_with_hierarchy("Foo", "foo-latest-prod-version", "Bar")
.create_consumer_version_tag("prod")
.create_consumer_version("not-latest-dev-version", tag_names: ["dev"])
Expand All @@ -31,14 +30,14 @@ def find_by_consumer_name_and_consumer_version_number(consumer_name, consumer_ve
.create_consumer_version("foo-latest-dev-version", tag_names: ["dev"])
.create_pact
.create_consumer("Baz")
.create_consumer_version("baz-latest-dev-version", tag_names: ["dev"])
.create_consumer_version("baz-latest-dev-version", tag_names: ["dev", "main"])
.create_pact
end

it "returns the latest pact for each consumer" do
expect(subject.size).to eq 2
expect(find_by_consumer_name_and_consumer_version_number("Foo", "foo-latest-dev-version")).to_not be nil
expect(find_by_consumer_name_and_consumer_version_number("Baz", "baz-latest-dev-version")).to_not be nil
expect(subject).to include(have_attributes(consumer_name: "Foo", consumer_version_number: "foo-latest-dev-version"))
expect(subject).to include(have_attributes(consumer_name: "Baz", consumer_version_number: "baz-latest-dev-version"))
expect(subject.all?(&:overall_latest?)).to be true
end
end
Expand Down

0 comments on commit 8847e44

Please sign in to comment.