Skip to content

Commit

Permalink
fix: pact selection verification options logging
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Apr 22, 2020
1 parent be6ab0f commit 9ff59f4
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 12 deletions.
15 changes: 3 additions & 12 deletions lib/pact/pact_broker/fetch_pact_uris_for_verification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions lib/pact/pact_broker/pact_selection_description.rb
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 spec/lib/pact/pact_broker/pact_selection_description_spec.rb
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

0 comments on commit 9ff59f4

Please sign in to comment.