Skip to content

Commit

Permalink
feat: add --log-dir and --log-level to CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Jun 23, 2020
1 parent 323f5eb commit 1cf71bb
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 26 deletions.
50 changes: 24 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,55 +41,53 @@ Usage:
Options:
-h, --provider-base-url=PROVIDER_BASE_URL
# Provider host URL
# Provider host URL
-c, [--provider-states-setup-url=PROVIDER_STATES_SETUP_URL]
# Base URL to setup the provider states at
# Base URL to setup the provider states at
[--pact-broker-base-url=PACT_BROKER_BASE_URL]
# Base URL of the Pact Broker from which to retrieve the pacts. Can also be set using the environment variable PACT_BROKER_BASE_URL.
# Base URL of the Pact Broker from which to retrieve the pacts. Can also be set using the environment variable PACT_BROKER_BASE_URL.
-n, [--broker-username=BROKER_USERNAME]
# Pact Broker basic auth username. Can also be set using the environment variable PACT_BROKER_USERNAME.
# Pact Broker basic auth username. Can also be set using the environment variable PACT_BROKER_USERNAME.
-p, [--broker-password=BROKER_PASSWORD]
# Pact Broker basic auth password. Can also be set using the environment variable PACT_BROKER_PASSWORD.
# Pact Broker basic auth password. Can also be set using the environment variable PACT_BROKER_PASSWORD.
-k, [--broker-token=BROKER_TOKEN]
# Pact Broker bearer token. Can also be set using the environment variable PACT_BROKER_TOKEN.
# Pact Broker bearer token. Can also be set using the environment variable PACT_BROKER_TOKEN.
[--provider=PROVIDER]
[--consumer-version-tag=TAG]
# Retrieve the latest pacts with this consumer version tag. Used in conjunction with --provider. May be specified multiple times.
[--consumer-version-selector=SELECTOR]
# JSON string specifying a selector that identifies which pacts to verify. May be specified multiple times. See below for further documentation.
# Retrieve the latest pacts with this consumer version tag. Used in conjunction with --provider. May be specified multiple times.
[--provider-version-tag=TAG]
# Tag to apply to the provider application version. May be specified multiple times.
# Tag to apply to the provider application version. May be specified multiple times.
-g, [--tag-with-git-branch], [--no-tag-with-git-branch]
# Tag provider version with the name of the current git branch. Default: false
-a, [--provider-app-version=PROVIDER_APP_VERSION]
# Provider application version, required when publishing verification results
# Provider application version, required when publishing verification results
-r, [--publish-verification-results], [--no-publish-verification-results]
# Publish verification results to the broker. This can also be enabled by setting the environment variable PACT_BROKER_PUBLISH_VERIFICATION_RESULTS=true
[--enable-pending], [--no-enable-pending]
# 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
# Publish verification results to the broker. This can also be enabled by setting the environment variable PACT_BROKER_PUBLISH_VERIFICATION_RESULTS=true
[--custom-provider-header=CUSTOM_PROVIDER_HEADER]
# Header to add to provider state set up and pact verification requests. eg 'Authorization: Basic cGFjdDpwYWN0'. May be specified multiple times.
# Header to add to provider state set up and pact verification requests. eg 'Authorization: Basic cGFjdDpwYWN0'. May be specified multiple times.
[--custom-middleware=FILE]
# Ruby file containing a class implementing Pact::ProviderVerifier::CustomMiddleware. This allows the response to be modified before replaying. Use with caution!
# Ruby file containing a class implementing Pact::ProviderVerifier::CustomMiddleware. This allows the response to be modified before replaying. Use with caution!
-v, [--verbose=VERBOSE]
# Verbose output
# Verbose output
-f, [--format=FORMATTER]
# RSpec formatter. Defaults to custom Pact formatter. Other options are json and RspecJunitFormatter (which outputs xml).
# RSpec formatter. Defaults to custom Pact formatter. Other options are json and RspecJunitFormatter (which outputs xml).
-o, [--out=FILE]
# Write output to a file instead of $stdout.
# Write output to a file instead of $stdout.
[--wait=SECONDS]
# The number of seconds to poll for the provider to become available before running the verification
# The number of seconds to poll for the provider to become available before running the verification
# Default: 0
# Default: 0
Description:
To verify a pact from a known URL, specify one or more PACT_URL arguments. If the pact
is hosted in a Pact Broker that uses authentication, specify the relevant
To verify a pact from a known URL, specify one or more PACT_URL arguments. If the
pact is hosted in a Pact Broker that uses authentication, specify the relevant
--broker-username/--broker-password or --broker-token fields. To dynamically fetch
pacts from a Pact Broker based on the provider name, specify the
--pact-broker-base-url, --provider and relevant authentication fields.
Selectors: These are specified using JSON strings. The keys are 'tag' (the name of the consumer
version tag) and 'latest' (true|false). For example '{"tag": "master", "latest":
true}'. For a detailed explanation of selectors, see https://pact.io/selectors
Selectors: These are specified using JSON strings. The keys are 'tag' (the name of the
consumer version tag) and 'latest' (true|false). For example '{"tag": "master",
"latest": true}'. For a detailed explanation of selectors, see
```

## Examples
Expand Down
2 changes: 2 additions & 0 deletions lib/pact/provider_verifier/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ def configure_output
require 'pact/configuration'
Pact.configuration.output_stream = Pact.configuration.error_stream
end
Pact.configuration.log_dir = options.log_dir if options.log_dir
Pact.configuration.logger.level = options.log_level.downcase.to_sym if options.log_level
end

def configure_reverse_proxy
Expand Down
2 changes: 2 additions & 0 deletions lib/pact/provider_verifier/cli/verify.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class AuthError < ::Thor::Error; end
method_option :ignore_failures, type: :boolean, default: false, desc: "If specified, process will always exit with exit code 0", hide: true
method_option :pact_urls, aliases: "-u", hide: true, :required => false
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
method_option :log_dir, desc: "The directory for the pact.log file"
method_option :log_level, desc: "The logging level"

def verify(*pact_urls)
validate_verify
Expand Down
16 changes: 16 additions & 0 deletions spec/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,22 @@
end
end

context "running verification a log dir" do
before do
FileUtils.rm_rf 'tmp/logs'
end

subject { `bundle exec bin/pact-provider-verifier ./test/me-they.json -a 1.0.100 --provider-base-url http://localhost:4567 --provider-states-setup-url http://localhost:4567/provider-state --log-dir tmp/logs --log-level info` }

it "the logs are written at the right level" do
subject
expect(File.exist?('tmp/logs/pact.log'))
logs = File.read('tmp/logs/pact.log')
expect(logs).to include ('INFO')
expect(logs).to_not include ('DEBUG')
end
end

after(:all) do
Process.kill 'KILL', @pipe.pid
end
Expand Down

0 comments on commit 1cf71bb

Please sign in to comment.