From bf9ed8146fe957b778be47b22add2d43c6c846e9 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Thu, 6 Sep 2018 09:36:29 +1000 Subject: [PATCH] feat: rename wip in CLI to ignore-failures and wip pacts to pending pacts --- .../aggregate_pact_configs.rb | 16 ++++++------- lib/pact/provider_verifier/app.rb | 2 +- lib/pact/provider_verifier/cli/verify.rb | 4 ++-- pact-provider-verifier.gemspec | 2 +- ...ntegration_with_pact_broker_config_spec.rb | 23 +++++++++--------- .../aggregate_pact_configs_spec.rb | 24 ++++++++++--------- .../pact/provider_verifier/cli/verify_spec.rb | 8 +++---- 7 files changed, 41 insertions(+), 38 deletions(-) diff --git a/lib/pact/provider_verifier/aggregate_pact_configs.rb b/lib/pact/provider_verifier/aggregate_pact_configs.rb index 0512841..843c29b 100644 --- a/lib/pact/provider_verifier/aggregate_pact_configs.rb +++ b/lib/pact/provider_verifier/aggregate_pact_configs.rb @@ -27,23 +27,23 @@ def call def pacts_urls_from_broker if pact_broker_base_url && provider_name - net_wip_pact_uris.collect{ | uri| OpenStruct.new(uri: uri, wip: true) } + - non_wip_pact_uris.collect{ | uri| OpenStruct.new(uri: uri) } + net_pending_pact_uris.collect{ | uri| OpenStruct.new(uri: uri, pending: true) } + + non_pending_pact_uris.collect{ | uri| OpenStruct.new(uri: uri) } else [] end end - def non_wip_pact_uris - @non_wip_pact_uris ||= Pact::PactBroker.fetch_pact_uris(provider_name, consumer_version_tags, pact_broker_base_url, http_client_options) + def non_pending_pact_uris + @non_pending_pact_uris ||= Pact::PactBroker.fetch_pact_uris(provider_name, consumer_version_tags, pact_broker_base_url, http_client_options) end - def wip_pact_uris - @wip_pact_uris ||= Pact::PactBroker.fetch_wip_pact_uris(provider_name, pact_broker_base_url, http_client_options) + def pending_pact_uris + @pending_pact_uris ||= Pact::PactBroker.fetch_pending_pact_uris(provider_name, pact_broker_base_url, http_client_options) end - def net_wip_pact_uris - wip_pact_uris - non_wip_pact_uris + def net_pending_pact_uris + pending_pact_uris - non_pending_pact_uris end end end diff --git a/lib/pact/provider_verifier/app.rb b/lib/pact/provider_verifier/app.rb index 9d83c99..9904534 100644 --- a/lib/pact/provider_verifier/app.rb +++ b/lib/pact/provider_verifier/app.rb @@ -102,7 +102,7 @@ def verify_pact config pact_broker_password: options.broker_password, format: options.format, out: options.out, - wip: config.wip + ignore_failures: config.pending } verify_options[:description] = ENV['PACT_DESCRIPTION'] if ENV['PACT_DESCRIPTION'] verify_options[:provider_state] = ENV['PACT_PROVIDER_STATE'] if ENV['PACT_PROVIDER_STATE'] diff --git a/lib/pact/provider_verifier/cli/verify.rb b/lib/pact/provider_verifier/cli/verify.rb index 764bbaa..6dfcd37 100644 --- a/lib/pact/provider_verifier/cli/verify.rb +++ b/lib/pact/provider_verifier/cli/verify.rb @@ -26,14 +26,14 @@ class InvalidArgumentsError < ::Thor::Error; end method_option :provider_states_url, aliases: "-s", :required => false, hide: true method_option :format, banner: "FORMATTER", aliases: "-f", desc: "RSpec formatter. Defaults to custom Pact formatter. Other options are json and RspecJunitFormatter (which outputs xml)." method_option :out, aliases: "-o", banner: "FILE", desc: "Write output to a file instead of $stdout." - method_option :wip, type: :boolean, default: false, desc: "If WIP, process will always exit with exit code 0", hide: true + method_option :ignore_failures, type: :boolean, default: false, desc: "If specified, process will always exit with exit code 0", hide: true method_option :pact_urls, aliases: "-u", hide: true, :required => false def verify(*pact_urls) validate_verify print_deprecation_warnings success = Pact::ProviderVerifier::App.call(merged_urls(pact_urls), options) - exit_with_non_zero_status if !success && !options.wip + exit_with_non_zero_status if !success && !options.ignore_failures end default_task :verify diff --git a/pact-provider-verifier.gemspec b/pact-provider-verifier.gemspec index 42350f8..ad0d82a 100644 --- a/pact-provider-verifier.gemspec +++ b/pact-provider-verifier.gemspec @@ -21,7 +21,7 @@ Gem::Specification.new do |gem| gem.license = 'MIT' gem.add_runtime_dependency 'rspec', '~> 3.5' - gem.add_runtime_dependency 'pact', '~>1.33', '>= 1.33.1' + gem.add_runtime_dependency 'pact', '~>1.33', '>= 1.33.2' gem.add_runtime_dependency 'pact-message', '~>0.4', '>=0.4.1' gem.add_runtime_dependency 'faraday', '~> 0.9', '>= 0.9.0' gem.add_runtime_dependency 'faraday_middleware', '~> 0.10' diff --git a/spec/integration_with_pact_broker_config_spec.rb b/spec/integration_with_pact_broker_config_spec.rb index f55ae2e..90d114c 100644 --- a/spec/integration_with_pact_broker_config_spec.rb +++ b/spec/integration_with_pact_broker_config_spec.rb @@ -2,14 +2,15 @@ describe "pact-provider-verifier with pact broker config" do before do - allow(Pact::PactBroker).to receive(:fetch_pact_uris).and_return(pact_uris) - allow(Pact::PactBroker).to receive(:fetch_wip_pact_uris).and_return(wip_pact_uris) + allow(pact_broker_api).to receive(:fetch_pact_uris).and_return(pact_uris) + allow(pact_broker_api).to receive(:fetch_pending_pact_uris).and_return(pending_pact_uris) allow(Pact::Cli::RunPactVerification).to receive(:call) end let(:args) { %W{pact-provider-verifier --provider Foo --consumer-version-tag master --consumer-version-tag prod --pact-broker-base-url http://localhost:5738 --broker-username username --broker-password password --provider-base-url http://localhost:4567} } - let(:pact_uris) { ["http://non-wip-pact"] } - let(:wip_pact_uris) { ["http://wip-pact"] } + let(:pact_uris) { ["http://non-pending-pact"] } + let(:pending_pact_uris) { ["http://pending-pact"] } + let(:pact_broker_api) { class_double(Pact::PactBroker).as_stubbed_const } subject do begin @@ -20,22 +21,22 @@ end it "fetches the pact URIs from the broker" do - expect(Pact::PactBroker).to receive(:fetch_pact_uris).with("Foo", ["master", "prod"], "http://localhost:5738", { username: "username", password: "password" }) + expect(pact_broker_api).to receive(:fetch_pact_uris).with("Foo", ["master", "prod"], "http://localhost:5738", { username: "username", password: "password" }) subject end - it "fetches the WIP pact URIs from the broker" do - expect(Pact::PactBroker).to receive(:fetch_wip_pact_uris).with("Foo", "http://localhost:5738", { username: "username", password: "password" }) + it "fetches the pending pacts URIs from the broker" do + expect(pact_broker_api).to receive(:fetch_pending_pact_uris).with("Foo", "http://localhost:5738", { username: "username", password: "password" }) subject end - it "verifies the non-wip pact" do - expect(Pact::Cli::RunPactVerification).to receive(:call).with(hash_including(pact_uri: "http://non-wip-pact", wip: nil)) + it "verifies the non-pending pact" do + expect(Pact::Cli::RunPactVerification).to receive(:call).with(hash_including(pact_uri: "http://non-pending-pact", ignore_failures: nil)) subject end - it "verifies the wip pact" do - expect(Pact::Cli::RunPactVerification).to receive(:call).with(hash_including(pact_uri: "http://wip-pact", wip: true)) + it "verifies the pending pact" do + expect(Pact::Cli::RunPactVerification).to receive(:call).with(hash_including(pact_uri: "http://pending-pact", ignore_failures: true)) subject end end diff --git a/spec/lib/pact/provider_verifier/aggregate_pact_configs_spec.rb b/spec/lib/pact/provider_verifier/aggregate_pact_configs_spec.rb index 98b4e07..111a2b1 100644 --- a/spec/lib/pact/provider_verifier/aggregate_pact_configs_spec.rb +++ b/spec/lib/pact/provider_verifier/aggregate_pact_configs_spec.rb @@ -12,15 +12,17 @@ module ProviderVerifier let(:pact_uris) { ["http://pact-2"] } - let(:wip_pact_uris) { ["http://pact-2", "http://pact-3"] } + let(:pending_pact_uris) { ["http://pact-2", "http://pact-3"] } + let(:pact_broker_api) { class_double(Pact::PactBroker).as_stubbed_const } subject { AggregatePactConfigs.call(pact_urls, provider_name, consumer_version_tags, pact_broker_base_url, http_client_options) } + context "with no broker config" do let(:pact_broker_base_url) { nil } it "does not make a call to a Pact Broker" do - expect(Pact::PactBroker).to_not receive(:fetch_pact_uris) + expect(pact_broker_api).to_not receive(:fetch_pact_uris) subject end @@ -31,25 +33,25 @@ module ProviderVerifier context "with broker config" do before do - allow(Pact::PactBroker).to receive(:fetch_pact_uris).and_return(pact_uris) - allow(Pact::PactBroker).to receive(:fetch_wip_pact_uris).and_return(wip_pact_uris) + allow(pact_broker_api).to receive(:fetch_pact_uris).and_return(pact_uris) + allow(pact_broker_api).to receive(:fetch_pending_pact_uris).and_return(pending_pact_uris) end - it "fetches the non wip pacts" do - expect(Pact::PactBroker).to receive(:fetch_pact_uris).with(provider_name, consumer_version_tags, pact_broker_base_url, http_client_options) + it "fetches the non pending pacts" do + expect(pact_broker_api).to receive(:fetch_pact_uris).with(provider_name, consumer_version_tags, pact_broker_base_url, http_client_options) subject end - it "fetches the wip pacts" do - expect(Pact::PactBroker).to receive(:fetch_wip_pact_uris).with(provider_name, pact_broker_base_url, http_client_options) + it "fetches the pending pacts" do + expect(pact_broker_api).to receive(:fetch_pending_pact_uris).with(provider_name, pact_broker_base_url, http_client_options) subject end - it "returns the wip urls first, with the non-wip pact URLs removed" do - expect(subject.first).to eq OpenStruct.new(uri: "http://pact-3", wip: true) + it "returns the pending urls first, with the non-pending pact URLs removed" do + expect(subject.first).to eq OpenStruct.new(uri: "http://pact-3", pending: true) end - it "returns the wip urls next" do + it "returns the pending urls next" do expect(subject[1]).to eq OpenStruct.new(uri: "http://pact-2") end diff --git a/spec/lib/pact/provider_verifier/cli/verify_spec.rb b/spec/lib/pact/provider_verifier/cli/verify_spec.rb index c0d5500..5982ce0 100644 --- a/spec/lib/pact/provider_verifier/cli/verify_spec.rb +++ b/spec/lib/pact/provider_verifier/cli/verify_spec.rb @@ -11,11 +11,11 @@ module CLI end let(:success) { true } - let(:wip) { 'wip' } + let(:ignore_failures) { 'ignore_failures' } let(:minimum_valid_options) do { provider_base_url: 'http://base', - wip: wip + ignore_failures: ignore_failures } end let(:pact_urls) { ['pact1.json', 'pact2.json'] } @@ -28,9 +28,9 @@ module CLI invoke_verify end - context "when --wip is not specified and App.call returns false" do + context "when --ignore-failures is not specified and App.call returns false" do let(:success) { false } - let(:wip) { nil } + let(:ignore_failures) { nil } it "exits with an error code" do begin