Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add consumer name to the selection description #229

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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