From 5127036333d6af9591f71b8be478490543a32fd1 Mon Sep 17 00:00:00 2001 From: Mateusz Derks Date: Wed, 25 Nov 2020 01:45:14 +0100 Subject: [PATCH] fix: add consumer name to the selection description (#229) * 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 --- lib/pact/pact_broker/pact_selection_description.rb | 4 ++-- .../pact/pact_broker/pact_selection_description_spec.rb | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/pact/pact_broker/pact_selection_description.rb b/lib/pact/pact_broker/pact_selection_description.rb index 0a61e1c8..2d8ed886 100644 --- a/lib/pact/pact_broker/pact_selection_description.rb +++ b/lib/pact/pact_broker/pact_selection_description.rb @@ -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]}" diff --git a/spec/lib/pact/pact_broker/pact_selection_description_spec.rb b/spec/lib/pact/pact_broker/pact_selection_description_spec.rb index 3cc07e8d..824af997 100644 --- a/spec/lib/pact/pact_broker/pact_selection_description_spec.rb +++ b/spec/lib/pact/pact_broker/pact_selection_description_spec.rb @@ -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" @@ -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