Skip to content

Commit

Permalink
feat: add support for the enable_pending flag
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Sep 11, 2020
1 parent c60828b commit 16866f4
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/pact/pact_broker/fetch_pact_uris_for_verification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 8 additions & 2 deletions lib/pact/provider/configuration/pact_verification_from_broker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down
11 changes: 11 additions & 0 deletions spec/lib/pact/pact_broker/fetch_pact_uris_for_verification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

0 comments on commit 16866f4

Please sign in to comment.