Skip to content

Commit

Permalink
feat: update descriptions for new consumer version selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Sep 7, 2021
1 parent 6dac2ac commit 0471397
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 5 deletions.
45 changes: 41 additions & 4 deletions lib/pact/pact_broker/pact_selection_description.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,48 @@ def pact_selection_description(provider, consumer_version_selectors, options, br
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
desc = nil
if selector[:tag]
desc = !selector[:latest] ? "all for tag #{selector[:tag]}" : "latest for tag #{selector[:tag]}"
desc = "#{desc} of #{selector[:consumer]}" if selector[:consumer]
elsif selector[:branch]
desc = "latest from branch #{selector[:branch]}"
desc = "#{desc} of #{selector[:consumer]}" if selector[:consumer]
elsif selector[:mainBranch]
desc = "latest from main branch"
desc = "#{desc} of #{selector[:consumer]}" if selector[:consumer]
elsif selector[:deployed]
if selector[:environment]
desc = "currently deployed to #{selector[:environment]}"
else
desc = "currently deployed"
end
desc = "#{selector[:consumer]} #{desc}" if selector[:consumer]
elsif selector[:released]
if selector[:environment]
desc = "currently released to #{selector[:environment]}"
else
desc = "currently released"
end
desc = "#{selector[:consumer]} #{desc}" if selector[:consumer]
elsif selector[:deployedOrReleased]
if selector[:environment]
desc = "currently deployed or released to #{selector[:environment]}"
else
desc = "currently deployed or released"
end
desc = "#{selector[:consumer]} #{desc}" if selector[:consumer]
elsif selector[:environment]
desc = "currently in #{selector[:environment]}"
desc = "#{selector[:consumer]} #{desc}" if selector[:consumer]
else
desc = selector.to_s
end

fallback = selector[:fallback] || selector[:fallbackTag]
name = fallback ? "#{selector[:tag]} (or #{fallback} if not found)" : selector[:tag]
[all_or_latest, name, consumer].compact.join(" ")
desc = "#{desc} (or #{fallback} if not found)" if fallback

desc
end.join(", ")
if options[:include_wip_pacts_since]
desc = "#{desc}, work in progress pacts created after #{options[:include_wip_pacts_since]}"
Expand Down
51 changes: 50 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 @@ -22,7 +22,56 @@ module PactBroker
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" }
it { is_expected.to eq "Fetching pacts for Bar from http://broker with the selection criteria: latest for tag cmaster of Foo, work in progress pacts created after 2020-01-01" }
end

describe "for branch" do
let(:consumer_version_selectors) { [{ branch: "feat/x", consumer: "Foo" }] }

it { is_expected.to include "latest from branch feat/x of Foo" }
end

describe "for main branch" do
let(:consumer_version_selectors) { [{ mainBranch: true, consumer: "Foo" }] }

it { is_expected.to include "latest from main branch of Foo" }
end

describe "for deployedOrReleased" do
let(:consumer_version_selectors) { [{ deployedOrReleased: true }] }

it { is_expected.to include "currently deployed or released" }
end

describe "for released in environment" do
let(:consumer_version_selectors) { [{ released: true, environment: "production" }] }

it { is_expected.to include "currently released to production" }
end

describe "for deployed in environment" do
let(:consumer_version_selectors) { [{ deployed: true, environment: "production" }] }

it { is_expected.to include "currently deployed to production" }
end

describe "for deployedOrReleased in environment" do
let(:consumer_version_selectors) { [{ deployedOrReleased: true, environment: "production" }] }

it { is_expected.to include "currently deployed or released to production" }
end

describe "in environment" do
let(:consumer_version_selectors) { [{ environment: "production" }] }

it { is_expected.to include "in production" }
end

describe "unknown" do
let(:consumer_version_selectors) { [{ branchPattern: "*foo" }] }

it { is_expected.to include "branchPattern" }
it { is_expected.to include "*foo" }
end
end
end
Expand Down

0 comments on commit 0471397

Please sign in to comment.