-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow pacts to be fetched from a Pact Broker by provider name, …
…including WIP pacts.
- Loading branch information
Showing
7 changed files
with
189 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
require 'pact/pact_broker' | ||
require 'ostruct' | ||
|
||
module Pact | ||
module ProviderVerifier | ||
class AggregatePactConfigs | ||
|
||
def self.call(pact_urls, provider_name, consumer_version_tags, pact_broker_base_url, http_client_options) | ||
new(pact_urls, provider_name, consumer_version_tags, pact_broker_base_url, http_client_options).call | ||
end | ||
|
||
def initialize(pact_urls, provider_name, consumer_version_tags, pact_broker_base_url, http_client_options) | ||
@pact_urls = pact_urls | ||
@provider_name = provider_name | ||
@consumer_version_tags = consumer_version_tags | ||
@pact_broker_base_url = pact_broker_base_url | ||
@http_client_options = http_client_options | ||
end | ||
|
||
def call | ||
pacts_urls_from_broker + pact_urls.collect{ |uri| OpenStruct.new(uri: uri) } | ||
end | ||
|
||
private | ||
|
||
attr_reader :pact_urls, :provider_name, :consumer_version_tags, :pact_broker_base_url, :http_client_options | ||
|
||
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) } | ||
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) | ||
end | ||
|
||
def wip_pact_uris | ||
@wip_pact_uris ||= Pact::PactBroker.fetch_wip_pact_uris(provider_name, pact_broker_base_url, http_client_options) | ||
end | ||
|
||
def net_wip_pact_uris | ||
wip_pact_uris - non_wip_pact_uris | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
bundle exec rackup -p 4567 spec/support/config.ru 2> /dev/null & | ||
pid=$! | ||
sleep 3 | ||
|
||
bundle exec bin/pact-provider-verifier --provider Bar --consumer-version-tag prod --pact-broker-base-url http://localhost:9292 -a 1.0.100 --provider-base-url http://localhost:4567 --provider-states-setup-url http://localhost:4567/provider-state | ||
|
||
kill -2 $pid | ||
wait $pid |
63 changes: 63 additions & 0 deletions
63
spec/lib/pact/provider_verifier/aggregate_pact_configs_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
require 'pact/provider_verifier/aggregate_pact_configs' | ||
|
||
module Pact | ||
module ProviderVerifier | ||
describe AggregatePactConfigs do | ||
describe ".call" do | ||
let(:pact_urls) { ["http://pact-1"] } | ||
let(:provider_name) { "Foo" } | ||
let(:consumer_version_tags) { ["master", "prod"] } | ||
let(:pact_broker_base_url) { "http://broker" } | ||
let(:http_client_options) { { "foo" => "bar"} } | ||
|
||
let(:pact_uris) { ["http://pact-2"] } | ||
|
||
let(:wip_pact_uris) { ["http://pact-2", "http://pact-3"] } | ||
|
||
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) | ||
subject | ||
end | ||
|
||
it "returns the hardcoded urls" do | ||
expect(subject).to eq [OpenStruct.new(uri: "http://pact-1")] | ||
end | ||
end | ||
|
||
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) | ||
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) | ||
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) | ||
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) | ||
end | ||
|
||
it "returns the wip urls next" do | ||
expect(subject[1]).to eq OpenStruct.new(uri: "http://pact-2") | ||
end | ||
|
||
it "returns the hardcoded urls last" do | ||
expect(subject.last).to eq OpenStruct.new(uri: "http://pact-1") | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters