Skip to content

Commit

Permalink
feat: add support for specifying the provider version branch
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Sep 8, 2021
1 parent e0a881d commit 7f53206
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 16 deletions.
10 changes: 6 additions & 4 deletions lib/pact/provider_verifier/aggregate_pact_configs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ module Pact
module ProviderVerifier
class AggregatePactConfigs

def self.call(pact_urls, provider_name, consumer_version_tags, consumer_version_selectors, provider_version_tags, pact_broker_base_url, http_client_options, options)
new(pact_urls, provider_name, consumer_version_tags, consumer_version_selectors, provider_version_tags, pact_broker_base_url, http_client_options, options).call
def self.call(pact_urls, provider_name, consumer_version_tags, consumer_version_selectors, provider_version_branch, provider_version_tags, pact_broker_base_url, http_client_options, options)
new(pact_urls, provider_name, consumer_version_tags, consumer_version_selectors, provider_version_branch, provider_version_tags, pact_broker_base_url, http_client_options, options).call
end

def initialize(pact_urls, provider_name, consumer_version_tags, consumer_version_selectors, provider_version_tags, pact_broker_base_url, http_client_options, options)
def initialize(pact_urls, provider_name, consumer_version_tags, consumer_version_selectors, provider_version_branch, provider_version_tags, pact_broker_base_url, http_client_options, options)
@pact_urls = pact_urls
@provider_name = provider_name
@consumer_version_tags = consumer_version_tags
@consumer_version_selectors = consumer_version_selectors
@provider_version_branch = provider_version_branch
@provider_version_tags = provider_version_tags
@pact_broker_base_url = pact_broker_base_url
@http_client_options = http_client_options
Expand All @@ -27,7 +28,7 @@ def call

private

attr_reader :pact_urls, :provider_name, :consumer_version_tags, :consumer_version_selectors, :provider_version_tags, :pact_broker_base_url, :http_client_options, :options
attr_reader :pact_urls, :provider_name, :consumer_version_tags, :consumer_version_selectors, :provider_version_branch, :provider_version_tags, :pact_broker_base_url, :http_client_options, :options

def specified_pact_uris
pact_urls.collect{ | url | Pact::PactBroker.build_pact_uri(url, http_client_options) }
Expand All @@ -45,6 +46,7 @@ def pacts_for_verification
@pacts_for_verification ||= Pact::PactBroker.fetch_pact_uris_for_verification(
provider_name,
aggregated_consumer_version_selectors,
provider_version_branch,
provider_version_tags,
pact_broker_base_url,
http_client_options,
Expand Down
4 changes: 3 additions & 1 deletion lib/pact/provider_verifier/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ class App

PROXY_PACT_HELPER = File.expand_path(File.join(File.dirname(__FILE__), "pact_helper.rb"))
EMPTY_ARRAY = [].freeze
attr_reader :pact_urls, :options, :consumer_version_tags, :provider_version_tags, :consumer_version_selectors, :publish_verification_results
attr_reader :pact_urls, :options, :consumer_version_tags, :provider_version_branch, :provider_version_tags, :consumer_version_selectors, :publish_verification_results

def initialize pact_urls, options = {}
@pact_urls = pact_urls
@options = options
@consumer_version_tags = options.consumer_version_tag || EMPTY_ARRAY
@provider_version_tags = merge_provider_version_tags(options)
@provider_version_branch = options.provider_version_branch
@consumer_version_selectors = parse_consumer_version_selectors(options.consumer_version_selector || EMPTY_ARRAY)
@publish_verification_results = options.publish_verification_results || ENV['PACT_BROKER_PUBLISH_VERIFICATION_RESULTS'] == 'true'
end
Expand Down Expand Up @@ -208,6 +209,7 @@ def all_pact_urls
options.provider,
consumer_version_tags,
consumer_version_selectors,
provider_version_branch,
provider_version_tags,
options.pact_broker_base_url || ENV['PACT_BROKER_BASE_URL'],
http_client_options,
Expand Down
1 change: 1 addition & 0 deletions lib/pact/provider_verifier/cli/verify.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class AuthError < ::Thor::Error; end
method_option :consumer_version_tag, type: :array, banner: "TAG", desc: "Retrieve the latest pacts with this consumer version tag. Used in conjunction with --provider. May be specified multiple times.", :required => false
method_option :consumer_version_selector, hide: true, type: :array, banner: "SELECTOR", desc: "JSON string specifying a selector that identifies which pacts to verify. May be specified multiple times. See below for further documentation.", :required => false
method_option :provider_version_tag, type: :array, banner: "TAG", desc: "Tag to apply to the provider application version. May be specified multiple times.", :required => false
method_option :provider_version_branch, banner: "BRANCH", desc: "The name of the branch the provider version belongs to.", :required => false
method_option :tag_with_git_branch, aliases: "-g", type: :boolean, default: false, required: false, desc: "Tag provider version with the name of the current git branch. Default: false"
method_option :provider_app_version, aliases: "-a", desc: "Provider application version, required when publishing verification results", :required => false
method_option :publish_verification_results, aliases: "-r", desc: "Publish verification results to the broker. This can also be enabled by setting the environment variable PACT_BROKER_PUBLISH_VERIFICATION_RESULTS=true", required: false, type: :boolean, default: false
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.55', '< 1.58'
gem.add_runtime_dependency 'pact', '~> 1.59'
gem.add_runtime_dependency 'pact-message', '~>0.5'
gem.add_runtime_dependency 'faraday', '>= 0.9.0', '<= 2.0'
gem.add_runtime_dependency 'faraday_middleware', '>= 0.10', '<= 2.0'
Expand Down
26 changes: 16 additions & 10 deletions script/dev/broker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,26 @@ sleep 3
# --consumer-version-selector '{"tag": "dev", "latest": true}' \
# --tag-with-git-branch \
# --verbose
export PACT_BROKER_PUBLISH_VERIFICATION_RESULTS=true
export PACT_BROKER_BASE_URL=https://test.pact.dius.com.au
export PACT_BROKER_USERNAME=dXfltyFMgNOFZAxr8io9wJ37iUpY42M
export PACT_BROKER_PASSWORD=O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1
# export PACT_BROKER_PUBLISH_VERIFICATION_RESULTS=false
# export PACT_BROKER_BASE_URL=https://bethtest.test.pactflow.io
# export PACT_BROKER_TOKEN=J4lCBjh5Z9vVEofBdrZnXw
export PACT_BROKER_PUBLISH_VERIFICATION_RESULTS=false
export PACT_BROKER_BASE_URL=http://localhost:9292
# export PACT_BROKER_TOKEN=J4lCBjh5Z9vVEofBdrZnXw
# --provider "Bar" \
# --provider-version-tag dev \
# --consumer-version-tag dev \
# --consumer-version-tag dev2 \
bundle exec bin/pact-provider-verifier \
--provider "Bar" \
--provider-version-tag dev \
--consumer-version-tag dev \
--consumer-version-tag dev2 \
--provider "Example API" \
--provider-app-version $(git rev-parse --short HEAD | xargs echo -n) \
--provider-version-branch "main" \
--provider-version-tag "foo" \
--provider-base-url http://localhost:4567 \
--include-wip-pacts-since 2018-01-01 \
--enable-pending --verbose \
--no-fail-if-no-pacts-found
--enable-pending \
--no-fail-if-no-pacts-found \
--verbose

echo "exit code is $?"

Expand Down
4 changes: 4 additions & 0 deletions spec/integration_with_pact_broker_config_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
require 'pact/provider_verifier/cli/verify'
require 'pact/pact_broker'
require 'pact/cli/run_pact_verification'

describe "pact-provider-verifier with pact broker config" do
before do
Expand All @@ -14,6 +16,7 @@
--provider Foo
--consumer-version-tag master
--consumer-version-tag prod
--provider-version-branch main
--provider-version-tag pmaster
--pact-broker-base-url http://localhost:5738
--broker-token token
Expand All @@ -34,6 +37,7 @@
expect(pact_broker_api).to receive(:fetch_pact_uris_for_verification).with(
"Foo",
[{ tag: "master", latest: true }, { tag: "prod", latest: true }],
"main",
["pmaster"],
"http://localhost:5738",
{ username: nil, password: nil, token: "token", verbose: false },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module ProviderVerifier
let(:consumer_version_tags) { ["master", "prod"] }
let(:selector) { double('selector') }
let(:consumer_version_selectors) { [selector] }
let(:provider_version_branch) { "main" }
let(:provider_version_tags) { ["dev"] }
let(:pact_broker_base_url) { "http://broker" }
let(:http_client_options) { { "foo" => "bar"} }
Expand All @@ -33,6 +34,7 @@ module ProviderVerifier
provider_name,
consumer_version_tags,
consumer_version_selectors,
provider_version_branch,
provider_version_tags,
pact_broker_base_url,
http_client_options,
Expand Down Expand Up @@ -76,6 +78,7 @@ module ProviderVerifier
expect(pact_broker_api).to receive(:fetch_pact_uris_for_verification).with(
provider_name,
aggregated_consumer_version_selectors,
provider_version_branch,
provider_version_tags,
pact_broker_base_url,
http_client_options,
Expand Down
1 change: 1 addition & 0 deletions spec/lib/pact/provider_verifier/app_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ module ProviderVerifier
anything,
anything,
anything,
anything,
["foo", "master"],
anything,
anything,
Expand Down

0 comments on commit 7f53206

Please sign in to comment.