Skip to content

Commit

Permalink
feat: allow verbose http logging to be turned on when fetching pacts …
Browse files Browse the repository at this point in the history
…URLs from the broker
  • Loading branch information
bethesque committed Jun 24, 2018
1 parent 7e82fd0 commit 436f3f2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ 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, :_basic_auth_options
attr_accessor :_provider_name, :_pact_broker_base_url, :_consumer_version_tags, :_basic_auth_options, :_verbose

def initialize(provider_name)
@_provider_name = provider_name
@_consumer_version_tags = []
@_verbose = false
end

dsl do
Expand All @@ -29,6 +30,10 @@ def pact_broker_base_url pact_broker_base_url, basic_auth_options = {}
def consumer_version_tags consumer_version_tags
self._consumer_version_tags = *consumer_version_tags
end

def verbose verbose
self._verbose = verbose
end
end

def finalize
Expand All @@ -39,7 +44,7 @@ def finalize
private

def create_pact_verification
fetch_pacts = Pact::PactBroker::FetchPacts.new(_provider_name, _consumer_version_tags, _pact_broker_base_url, _basic_auth_options)
fetch_pacts = Pact::PactBroker::FetchPacts.new(_provider_name, _consumer_version_tags, _pact_broker_base_url, _basic_auth_options.merge(verbose: _verbose))
Pact.provider_world.add_pact_uri_source fetch_pacts
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ module Configuration
PactVerificationFromBroker.build(provider_name) do
pact_broker_base_url base_url, basic_auth_options
consumer_version_tags tags
verbose true
end
end

let(:fetch_pacts) { double('FetchPacts') }
let(:options) { basic_auth_options.merge(verbose: true) }

it "creates a instance of Pact::PactBroker::FetchPacts" do
expect(Pact::PactBroker::FetchPacts).to receive(:new).with(provider_name, tags, base_url, basic_auth_options)
expect(Pact::PactBroker::FetchPacts).to receive(:new).with(provider_name, tags, base_url, options)
subject
end

Expand Down Expand Up @@ -85,6 +87,21 @@ module Configuration
subject
end
end

context "when no verbose flag is provided" do
subject do
PactVerificationFromBroker.build(provider_name) do
pact_broker_base_url base_url
end
end

let(:fetch_pacts) { double('FetchPacts') }

it "creates an instance of FetchPacts with verbose: false" do
expect(Pact::PactBroker::FetchPacts).to receive(:new).with(anything, anything, anything, hash_including(verbose: false))
subject
end
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ module VerificationResults

context "when the connection can't be made" do
it "raises a PublicationError error" do
allow(Net::HTTP).to receive(:start).and_raise(SocketError)
allow(Net::HTTP).to receive(:new).and_raise(SocketError)
expect{ subject }.to raise_error(PublicationError, /Failed to publish verification/)
end
end
Expand Down

0 comments on commit 436f3f2

Please sign in to comment.