diff --git a/lib/pact/pact_broker/fetch_pact_uris_for_verification.rb b/lib/pact/pact_broker/fetch_pact_uris_for_verification.rb index 166c5f96..46616340 100644 --- a/lib/pact/pact_broker/fetch_pact_uris_for_verification.rb +++ b/lib/pact/pact_broker/fetch_pact_uris_for_verification.rb @@ -4,10 +4,12 @@ require 'pact/errors' require 'pact/pact_broker/fetch_pacts' require 'pact/pact_broker/notices' +require 'pact/pact_broker/pact_selection_description' module Pact module PactBroker class FetchPactURIsForVerification + include PactSelectionDescription attr_reader :provider, :consumer_version_selectors, :provider_version_tags, :broker_base_url, :http_client_options, :http_client, :options PACTS_FOR_VERIFICATION_RELATION = 'beta:provider-pacts-for-verification'.freeze @@ -84,18 +86,7 @@ def symbolize_keys(hash) end def log_message - latest = consumer_version_selectors.any? ? "" : "latest " - message = "INFO: 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[:all] ? "all for tag" : "latest for tag" - # TODO support fallback - name = selector[:fallback] ? "#{selector[:tag]} (or #{selector[:fallback]} if not found)" : selector[:tag] - "#{all_or_latest} #{name}" - end.join(", ") - message << ": #{desc}" - end - Pact.configuration.output_stream.puts message + Pact.configuration.output_stream.puts "INFO: #{pact_selection_description(provider, consumer_version_selectors, options, broker_base_url)}" end end end diff --git a/lib/pact/pact_broker/pact_selection_description.rb b/lib/pact/pact_broker/pact_selection_description.rb new file mode 100644 index 00000000..39adb1df --- /dev/null +++ b/lib/pact/pact_broker/pact_selection_description.rb @@ -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 diff --git a/spec/lib/pact/pact_broker/pact_selection_description_spec.rb b/spec/lib/pact/pact_broker/pact_selection_description_spec.rb new file mode 100644 index 00000000..5d934491 --- /dev/null +++ b/spec/lib/pact/pact_broker/pact_selection_description_spec.rb @@ -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