forked from pact-foundation/pact-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: pact selection verification options logging
- Loading branch information
Showing
3 changed files
with
51 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
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" | ||
# TODO support fallback | ||
fallback = selector[:fallback] || selector[:fallbackTag] | ||
name = fallback ? "#{selector[:tag]} (or #{fallback} if not found)" : selector[:tag] | ||
"#{all_or_latest} #{name}" | ||
end.join(", ") | ||
if options[:include_wip_pacts_since] | ||
desc = "#{desc}, work in progress pacts created after #{options[:include_wip_pacts_since]}" | ||
end | ||
message << "#{desc}" | ||
end | ||
message | ||
end | ||
end | ||
end | ||
end |
24 changes: 24 additions & 0 deletions
24
spec/lib/pact/pact_broker/pact_selection_description_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require 'pact/pact_broker/pact_selection_description' | ||
|
||
module Pact | ||
module PactBroker | ||
describe PactSelectionDescription do | ||
include PactSelectionDescription | ||
|
||
describe "#pact_selection_description" do | ||
let(:provider) { "Bar" } | ||
let(:consumer_version_selectors) { [{ tag: "cmaster", latest: true, fallbackTag: "master"}, { tag: "prod"}] } | ||
let(:options) do | ||
{ | ||
include_wip_pacts_since: "2020-01-01" | ||
} | ||
end | ||
let(:broker_base_url) { "http://broker" } | ||
|
||
subject { pact_selection_description(provider, consumer_version_selectors, options, broker_base_url).tap { |it| puts it } } | ||
|
||
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" } | ||
end | ||
end | ||
end | ||
end |