Skip to content

Commit

Permalink
feat: rename wip in CLI to ignore-failures and wip pacts to pending p…
Browse files Browse the repository at this point in the history
…acts
  • Loading branch information
bethesque committed Sep 5, 2018
1 parent 5c7ddf0 commit bf9ed81
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 38 deletions.
16 changes: 8 additions & 8 deletions lib/pact/provider_verifier/aggregate_pact_configs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/pact/provider_verifier/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
4 changes: 2 additions & 2 deletions lib/pact/provider_verifier/cli/verify.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pact-provider-verifier.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
23 changes: 12 additions & 11 deletions spec/integration_with_pact_broker_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
24 changes: 13 additions & 11 deletions spec/lib/pact/provider_verifier/aggregate_pact_configs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
8 changes: 4 additions & 4 deletions spec/lib/pact/provider_verifier/cli/verify_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'] }
Expand All @@ -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
Expand Down

0 comments on commit bf9ed81

Please sign in to comment.