From 9238e4c166e7dbb4e1efecfa19dcef41278eff0f Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Wed, 27 Jan 2021 09:17:05 +1100 Subject: [PATCH] feat: allow verbose flag to be set when publishing verifications --- lib/pact/cli.rb | 1 + lib/pact/cli/run_pact_verification.rb | 1 + lib/pact/provider/pact_spec_runner.rb | 1 + lib/pact/provider/rspec.rb | 2 +- lib/pact/provider/rspec/pact_broker_formatter.rb | 2 +- lib/pact/provider/verification_results/publish.rb | 8 ++++---- lib/pact/provider/verification_results/publish_all.rb | 11 ++++++----- lib/pact/provider/world.rb | 2 +- 8 files changed, 16 insertions(+), 12 deletions(-) diff --git a/lib/pact/cli.rb b/lib/pact/cli.rb index c8949d88..5541139e 100755 --- a/lib/pact/cli.rb +++ b/lib/pact/cli.rb @@ -16,6 +16,7 @@ def self.exit_on_failure? # Thor 1.0 deprecation guard method_option :pact_broker_password, aliases: "-w", desc: "Pact broker password" method_option :pact_broker_token, aliases: "-k", desc: "Pact broker token" method_option :backtrace, aliases: "-b", desc: "Show full backtrace", :default => false, :type => :boolean + method_option :verbose, aliases: "-v", desc: "Show verbose HTTP logging", :default => false, :type => :boolean method_option :interactions_replay_order, aliases: "-o", desc: "Interactions replay order: randomised or recorded (default)", default: Pact.configuration.interactions_replay_order diff --git a/lib/pact/cli/run_pact_verification.rb b/lib/pact/cli/run_pact_verification.rb index 21f70384..333120b5 100644 --- a/lib/pact/cli/run_pact_verification.rb +++ b/lib/pact/cli/run_pact_verification.rb @@ -79,6 +79,7 @@ def run_with_configured_pacts_from_pact_helper def pact_spec_options { full_backtrace: options[:backtrace], + verbose: options[:verbose] || ENV['VERBOSE'] == 'true', criteria: SpecCriteria.call(options), format: options[:format], out: options[:out], diff --git a/lib/pact/provider/pact_spec_runner.rb b/lib/pact/provider/pact_spec_runner.rb index 85afdc9c..cc7e50a9 100644 --- a/lib/pact/provider/pact_spec_runner.rb +++ b/lib/pact/provider/pact_spec_runner.rb @@ -75,6 +75,7 @@ def configure_rspec end # For the Pact::Provider::RSpec::PactBrokerFormatter + Pact.provider_world.verbose = options[:verbose] Pact.provider_world.pact_sources = pact_sources jsons = pact_jsons executing_with_ruby = executing_with_ruby? diff --git a/lib/pact/provider/rspec.rb b/lib/pact/provider/rspec.rb index 416a4703..a6e7372c 100644 --- a/lib/pact/provider/rspec.rb +++ b/lib/pact/provider/rspec.rb @@ -36,7 +36,7 @@ def honour_pactfile pact_source, pact_json, options pact_source: pact_source, consumer_contract: consumer_contract, criteria: options[:criteria] - ) + ) end end diff --git a/lib/pact/provider/rspec/pact_broker_formatter.rb b/lib/pact/provider/rspec/pact_broker_formatter.rb index 1a3ce532..e655b8fd 100644 --- a/lib/pact/provider/rspec/pact_broker_formatter.rb +++ b/lib/pact/provider/rspec/pact_broker_formatter.rb @@ -25,7 +25,7 @@ def stop(notification) end def close(_notification) - Pact::Provider::VerificationResults::PublishAll.call(Pact.provider_world.pact_sources, output_hash) + Pact::Provider::VerificationResults::PublishAll.call(Pact.provider_world.pact_sources, output_hash, { verbose: Pact.provider_world.verbose }) end private diff --git a/lib/pact/provider/verification_results/publish.rb b/lib/pact/provider/verification_results/publish.rb index 86924fa1..6a388b97 100644 --- a/lib/pact/provider/verification_results/publish.rb +++ b/lib/pact/provider/verification_results/publish.rb @@ -17,15 +17,15 @@ class Publish PROVIDER_RELATION = 'pb:provider'.freeze VERSION_TAG_RELATION = 'pb:version-tag'.freeze - def self.call pact_source, verification_result - new(pact_source, verification_result).call + def self.call pact_source, verification_result, options = {} + new(pact_source, verification_result, options).call end - def initialize pact_source, verification_result + def initialize pact_source, verification_result, options = {} @pact_source = pact_source @verification_result = verification_result http_client_options = pact_source.uri.options.reject{ |k, v| ![:username, :password, :token].include?(k) } - @http_client = Pact::Hal::HttpClient.new(http_client_options) + @http_client = Pact::Hal::HttpClient.new(http_client_options.merge(verbose: options[:verbose])) @pact_entity = Pact::Hal::Entity.new(pact_source.uri, pact_source.pact_hash, http_client) end diff --git a/lib/pact/provider/verification_results/publish_all.rb b/lib/pact/provider/verification_results/publish_all.rb index 46312cea..94faab99 100644 --- a/lib/pact/provider/verification_results/publish_all.rb +++ b/lib/pact/provider/verification_results/publish_all.rb @@ -6,20 +6,21 @@ module Provider module VerificationResults class PublishAll - def self.call pact_sources, test_results_hash - new(pact_sources, test_results_hash).call + def self.call pact_sources, test_results_hash, options = {} + new(pact_sources, test_results_hash, options).call end - def initialize pact_sources, test_results_hash + def initialize pact_sources, test_results_hash, options = {} @pact_sources = pact_sources @test_results_hash = test_results_hash + @options = options end def call verification_results.collect do | (pact_source, verification_result) | published = false begin - published = Publish.call(pact_source, verification_result) + published = Publish.call(pact_source, verification_result, { verbose: options[:verbose] }) ensure print_after_verification_notices(pact_source, verification_result, published) end @@ -42,7 +43,7 @@ def print_after_verification_notices(pact_source, verification_result, published end end - attr_reader :pact_sources, :test_results_hash + attr_reader :pact_sources, :test_results_hash, :options end end end diff --git a/lib/pact/provider/world.rb b/lib/pact/provider/world.rb index d9ee3254..f6168d36 100644 --- a/lib/pact/provider/world.rb +++ b/lib/pact/provider/world.rb @@ -14,7 +14,7 @@ def self.clear_provider_world module Provider class World - attr_accessor :pact_sources, :failed_examples + attr_accessor :pact_sources, :failed_examples, :verbose def provider_states @provider_states_proxy ||= Pact::Provider::State::ProviderStateProxy.new