From 16866f440afdad355266e0eb9685529d8a995de3 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Fri, 11 Sep 2020 20:02:43 +1000 Subject: [PATCH] feat: add support for the enable_pending flag --- .../pact_broker/fetch_pact_uris_for_verification.rb | 2 +- .../configuration/pact_verification_from_broker.rb | 10 ++++++++-- .../fetch_pact_uris_for_verification_spec.rb | 11 +++++++++++ .../pact_verification_from_broker_spec.rb | 12 +++++++----- 4 files changed, 27 insertions(+), 8 deletions(-) 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 46616340..3c11a3c8 100644 --- a/lib/pact/pact_broker/fetch_pact_uris_for_verification.rb +++ b/lib/pact/pact_broker/fetch_pact_uris_for_verification.rb @@ -22,7 +22,7 @@ class FetchPactURIsForVerification def initialize(provider, consumer_version_selectors, provider_version_tags, broker_base_url, http_client_options, options = {}) @provider = provider @consumer_version_selectors = consumer_version_selectors || [] - @provider_version_tags = provider_version_tags || [] + @provider_version_tags = [*provider_version_tags] @http_client_options = http_client_options @broker_base_url = broker_base_url @http_client = Pact::Hal::HttpClient.new(http_client_options) diff --git a/lib/pact/provider/configuration/pact_verification_from_broker.rb b/lib/pact/provider/configuration/pact_verification_from_broker.rb index ea688944..35636f23 100644 --- a/lib/pact/provider/configuration/pact_verification_from_broker.rb +++ b/lib/pact/provider/configuration/pact_verification_from_broker.rb @@ -14,12 +14,13 @@ class PactVerificationFromBroker # in parent scope, it will clash with these ones, # so put an underscore in front of the name to be safer. - attr_accessor :_provider_name, :_pact_broker_base_url, :_consumer_version_tags, :_provider_version_tags, :_basic_auth_options, :_verbose + attr_accessor :_provider_name, :_pact_broker_base_url, :_consumer_version_tags, :_provider_version_tags, :_basic_auth_options, :_enable_pending, :_verbose def initialize(provider_name, provider_version_tags) @_provider_name = provider_name @_provider_version_tags = provider_version_tags @_consumer_version_tags = [] + @_enable_pending = false @_verbose = false end @@ -33,6 +34,10 @@ def consumer_version_tags consumer_version_tags self._consumer_version_tags = *consumer_version_tags end + def enable_pending enable_pending + self._enable_pending = enable_pending + end + def verbose verbose self._verbose = verbose end @@ -51,7 +56,8 @@ def create_pact_verification consumer_version_selectors, _provider_version_tags, _pact_broker_base_url, - _basic_auth_options.merge(verbose: _verbose) + _basic_auth_options.merge(verbose: _verbose), + { include_pending_status: _enable_pending } ) Pact.provider_world.add_pact_uri_source fetch_pacts diff --git a/spec/lib/pact/pact_broker/fetch_pact_uris_for_verification_spec.rb b/spec/lib/pact/pact_broker/fetch_pact_uris_for_verification_spec.rb index 9e8a0688..3f42f8b3 100644 --- a/spec/lib/pact/pact_broker/fetch_pact_uris_for_verification_spec.rb +++ b/spec/lib/pact/pact_broker/fetch_pact_uris_for_verification_spec.rb @@ -35,6 +35,17 @@ module PactBroker end end + context "when a single tag is provided instead of an array" do + + let(:provider_version_tags) { "pmaster" } + + subject { FetchPactURIsForVerification.new(provider, consumer_version_selectors, provider_version_tags, broker_base_url, http_client_options)} + + it "wraps an array around it" do + expect(subject.provider_version_tags).to eq ["pmaster"] + end + end + context "when the beta:provider-pacts-for-verification relation does not exist" do before do allow(FetchPacts).to receive(:call) diff --git a/spec/lib/pact/provider/configuration/pact_verification_from_broker_spec.rb b/spec/lib/pact/provider/configuration/pact_verification_from_broker_spec.rb index f684fe27..64ba35c1 100644 --- a/spec/lib/pact/provider/configuration/pact_verification_from_broker_spec.rb +++ b/spec/lib/pact/provider/configuration/pact_verification_from_broker_spec.rb @@ -26,16 +26,18 @@ module Configuration PactVerificationFromBroker.build(provider_name, provider_version_tags) do pact_broker_base_url base_url, basic_auth_options consumer_version_tags tags + enable_pending true verbose true end end let(:fetch_pacts) { double('FetchPacts') } - let(:options) { basic_auth_options.merge(verbose: true) } + let(:basic_auth_opts) { basic_auth_options.merge(verbose: true) } + let(:options) { { include_pending_status: true }} let(:consumer_version_selectors) { [ { tag: 'master', latest: true }] } it "creates a instance of Pact::PactBroker::FetchPactURIsForVerification" do - expect(Pact::PactBroker::FetchPactURIsForVerification).to receive(:new).with(provider_name, consumer_version_selectors, provider_version_tags, base_url, options) + expect(Pact::PactBroker::FetchPactURIsForVerification).to receive(:new).with(provider_name, consumer_version_selectors, provider_version_tags, base_url, basic_auth_opts, options) subject end @@ -70,7 +72,7 @@ module Configuration let(:fetch_pacts) { double('FetchPacts') } it "coerces the value into an array" do - expect(Pact::PactBroker::FetchPactURIsForVerification).to receive(:new).with(anything, [{ tag: "master", latest: true}], anything, anything, anything) + expect(Pact::PactBroker::FetchPactURIsForVerification).to receive(:new).with(anything, [{ tag: "master", latest: true}], anything, anything, anything, anything) subject end end @@ -85,7 +87,7 @@ module Configuration let(:fetch_pacts) { double('FetchPacts') } it "creates an instance of FetchPacts with an emtpy array for the consumer_version_tags" do - expect(Pact::PactBroker::FetchPactURIsForVerification).to receive(:new).with(anything, [], anything, anything, anything) + expect(Pact::PactBroker::FetchPactURIsForVerification).to receive(:new).with(anything, [], anything, anything, anything, anything) subject end end @@ -100,7 +102,7 @@ module Configuration let(:fetch_pacts) { double('FetchPacts') } it "creates an instance of FetchPactURIsForVerification with verbose: false" do - expect(Pact::PactBroker::FetchPactURIsForVerification).to receive(:new).with(anything, anything, anything, anything, hash_including(verbose: false)) + expect(Pact::PactBroker::FetchPactURIsForVerification).to receive(:new).with(anything, anything, anything, anything, hash_including(verbose: false), anything) subject end end