Skip to content

Commit

Permalink
feat(cli): add --include-wip-pacts-since (hidden until publicly relea…
Browse files Browse the repository at this point in the history
…sed)
  • Loading branch information
bethesque committed Feb 19, 2020
1 parent 3b20146 commit 3109ce2
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 17 deletions.
5 changes: 4 additions & 1 deletion lib/pact/provider_verifier/aggregate_pact_configs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ def aggregated_consumer_version_selectors
end

def pact_options
{ include_pending_status: options[:enable_pending] }
{
include_pending_status: options[:enable_pending],
include_wip_pacts_since: options[:include_wip_pacts_since]
}
end
end
end
Expand Down
7 changes: 5 additions & 2 deletions lib/pact/provider_verifier/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ def all_pact_urls
token: options.broker_token || ENV['PACT_BROKER_TOKEN'],
verbose: options.verbose
}
opts = {
enable_pending: options.enable_pending,
include_wip_pacts_since: options.include_wip_pacts_since
}
AggregatePactConfigs.call(
pact_urls,
options.provider,
Expand All @@ -198,8 +202,7 @@ def all_pact_urls
provider_version_tags,
options.pact_broker_base_url || ENV['PACT_BROKER_BASE_URL'],
http_client_options,
{ enable_pending: options.enable_pending }
)
opts)
end

def require_pact_project_pact_helper
Expand Down
24 changes: 19 additions & 5 deletions lib/pact/provider_verifier/cli/verify.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class AuthError < ::Thor::Error; end
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
method_option :enable_pending, desc: "Allow pacts which are in pending state to be verified without causing the overall task to fail. For more information, see https://pact.io/pending", required: false, type: :boolean, default: false
method_option :include_wip_pacts_since, desc: "", hide: true
method_option :custom_provider_header, type: :array, banner: 'CUSTOM_PROVIDER_HEADER', desc: "Header to add to provider state set up and pact verification requests. eg 'Authorization: Basic cGFjdDpwYWN0'. May be specified multiple times.", :required => false
method_option :custom_middleware, type: :array, banner: 'FILE', desc: "Ruby file containing a class implementing Pact::ProviderVerifier::CustomMiddleware. This allows the response to be modified before replaying. Use with caution!", :required => false
method_option :monkeypatch, hide: true, type: :array, :required => false
Expand All @@ -50,7 +51,6 @@ class AuthError < ::Thor::Error; end
method_option :wait, banner: "SECONDS", required: false, type: :numeric, desc: "The number of seconds to poll for the provider to become available before running the verification", default: 0

def verify(*pact_urls)
validate_credentials
validate_verify
print_deprecation_warnings
success = Pact::ProviderVerifier::App.call(merged_urls(pact_urls), options)
Expand All @@ -77,17 +77,31 @@ def print_deprecation_warnings
end
end

def validate_verify
if options.pact_broker_base_url && (options.provider.nil? || options.provider == "")
raise InvalidArgumentsError, "No value provided for required option '--provider'"
end
validate_consumer_version_selectors
validate_wip_since_date
validate_credentials
end

def validate_credentials
if (options.broker_username || ENV['PACT_BROKER_USERNAME']) && (options.broker_token || ENV['PACT_BROKER_TOKEN'])
raise AuthError, "You cannot provide both a username/password and a bearer token. If your Pact Broker uses a bearer token, please remove the username and password configuration."
end
end

def validate_verify
if options.pact_broker_base_url && (options.provider.nil? || options.provider == "")
raise InvalidArgumentsError, "No value provided for required option '--provider'"
def validate_wip_since_date
require 'date'

if options.include_wip_pacts_since
begin
DateTime.parse(options.include_wip_pacts_since)
rescue ArgumentError
raise InvalidArgumentsError, "The value provided for --include-wip-pacts-since could not be parsed to a DateTime. Please provide a value in the format %Y-%m-%d or %Y-%m-%dT%H:%M:%S.000%:z"
end
end
validate_consumer_version_selectors
end

def validate_consumer_version_selectors
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.46', '>= 1.46.1'
gem.add_runtime_dependency 'pact', '~> 1.49'
gem.add_runtime_dependency 'pact-message', '~>0.5'
gem.add_runtime_dependency 'faraday', '~> 0.9', '>= 0.9.0'
gem.add_runtime_dependency 'faraday_middleware', '~> 0.10'
Expand Down
4 changes: 3 additions & 1 deletion script/dev/broker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ export PACT_BROKER_USERNAME=dXfltyFMgNOFZAxr8io9wJ37iUpY42M
export PACT_BROKER_PASSWORD=O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1
bundle exec bin/pact-provider-verifier \
--provider "Bar" \
--provider-version-tag dev \
--consumer-version-tag dev \
--consumer-version-tag dev2 \
--provider-app-version $(git rev-parse --short HEAD | xargs echo -n) \
--provider-base-url http://localhost:4567 \
--enable-pending
--include-wip-pacts-since 2018-01-01 \
--enable-pending --verbose

kill -2 $pid
wait $pid
49 changes: 42 additions & 7 deletions spec/lib/pact/provider_verifier/cli/verify_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ module CLI
end

context "with multiple --consumer-version-selector" do
before do
subject.options = OpenStruct.new(options)
end

let(:options) do
minimum_valid_options.merge(
pact_broker_base_url: "http://broker",
Expand All @@ -129,9 +133,6 @@ module CLI
)
end

before do
subject.options = OpenStruct.new(options)
end

it "parses the JSON strings to hashes" do
expect(Pact::ProviderVerifier::App).to receive(:call).with(
Expand All @@ -140,7 +141,45 @@ module CLI
end
end

context "with --include-wip-pacts-since" do
before do
subject.options = OpenStruct.new(options)
end

context "with a valid date time" do
let(:options) do
minimum_valid_options.merge(
include_wip_pacts_since: "2020-02-19T19:31:18.000+11:00"
)
end

it "passes the argument to the app" do
expect(Pact::ProviderVerifier::App).to receive(:call).with(
pact_urls, OpenStruct.new(options))
invoke_verify
end
end

context "with an invalid date time" do
let(:options) do
minimum_valid_options.merge(
include_wip_pacts_since: "foo"
)
end

it "raises an error" do
expect { invoke_verify }.to raise_error Verify::InvalidArgumentsError, /DateTime/
end
end


end

context "with --consumer-version-selector that is invalid JSON" do
before do
subject.options = OpenStruct.new(options)
end

let(:options) do
minimum_valid_options.merge(
pact_broker_base_url: "http://broker",
Expand All @@ -149,10 +188,6 @@ module CLI
)
end

before do
subject.options = OpenStruct.new(options)
end

it "raises an InvalidArgumentsError" do
expect { subject.verify }.to raise_error Verify::InvalidArgumentsError, /Invalid JSON string/
end
Expand Down

0 comments on commit 3109ce2

Please sign in to comment.