Skip to content

Commit

Permalink
fix: add consumer name to the selection description (#229)
Browse files Browse the repository at this point in the history
* fix(pact_selection_description): support consumer name selection

When consumer_version_selection specifies consumer name, the name is
added to the description too.

* fix(pact_selection_description) remove unused variable
  • Loading branch information
ertrzyiks authored Nov 25, 2020
1 parent 37d1029 commit 5127036
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/pact/pact_broker/pact_selection_description.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ module Pact
module PactBroker
module PactSelectionDescription
def pact_selection_description(provider, consumer_version_selectors, options, broker_base_url)
latest = consumer_version_selectors.any? ? "" : "latest "
message = "Fetching pacts for #{provider} from #{broker_base_url} with the selection criteria: "
if consumer_version_selectors.any?
desc = consumer_version_selectors.collect do |selector|
all_or_latest = !selector[:latest] ? "all for tag" : "latest for tag"
consumer = selector[:consumer] ? "of consumer #{selector[:consumer]}" : nil
fallback = selector[:fallback] || selector[:fallbackTag]
name = fallback ? "#{selector[:tag]} (or #{fallback} if not found)" : selector[:tag]
"#{all_or_latest} #{name}"
[all_or_latest, name, consumer].compact.join(" ")
end.join(", ")
if options[:include_wip_pacts_since]
desc = "#{desc}, work in progress pacts created after #{options[:include_wip_pacts_since]}"
Expand Down
8 changes: 7 additions & 1 deletion spec/lib/pact/pact_broker/pact_selection_description_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module PactBroker

describe "#pact_selection_description" do
let(:provider) { "Bar" }
let(:consumer_version_selectors) { [{ tag: "cmaster", latest: true, fallbackTag: "master"}, { tag: "prod"}] }
let(:consumer_version_selectors) { [{ tag: "cmaster", latest: true, fallbackTag: "master" }, { tag: "prod" }] }
let(:options) do
{
include_wip_pacts_since: "2020-01-01"
Expand All @@ -18,6 +18,12 @@ module PactBroker
subject { pact_selection_description(provider, consumer_version_selectors, options, broker_base_url) }

it { is_expected.to eq "Fetching pacts for Bar from http://broker with the selection criteria: latest for tag cmaster (or master if not found), all for tag prod, work in progress pacts created after 2020-01-01" }

describe "when consumer selector specifies a consumer name" do
let(:consumer_version_selectors) { [{ tag: "cmaster", latest: true, consumer: "Foo" }] }

it { is_expected.to eq "Fetching pacts for Bar from http://broker with the selection criteria: latest for tag cmaster of consumer Foo, work in progress pacts created after 2020-01-01" }
end
end
end
end
Expand Down

0 comments on commit 5127036

Please sign in to comment.