Skip to content

Commit

Permalink
Merge pull request #170 from alecgerona/feat/consumer-version-selector
Browse files Browse the repository at this point in the history
feat: consumer version selector
  • Loading branch information
elliottmurray authored Aug 27, 2020
2 parents 06d1090 + 05c5e41 commit a594e22
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 15 deletions.
39 changes: 38 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,15 @@ requests.

The URL which should be called to setup a specific provider state before a Pact is verified. This URL will be called with a POST request, and the JSON body `{consumer: 'Consumer name', state: 'a thing exists'}`.

###### --pact-broker-url

Base URl for the Pact Broker instance to publish pacts to. Can also be specified via the environment variable
`PACT_BROKER_BASE_URL`.

###### --pact-broker-username

The username to use when contacting the Pact Broker.
The username to use when contacting the Pact Broker. Can also be specified via the environment variable
`PACT_BROKER_USERNAME`.

###### --pact-broker-password

Expand All @@ -361,6 +367,37 @@ as the environment variable `PACT_BROKER_PASSWORD`.
The bearer token to use when contacting the Pact Broker. You can also specify this value
as the environment variable `PACT_BROKER_TOKEN`.

###### --consumer-version-tag

Retrieve the latest pacts with this consumer version tag. Used in conjunction with `--provider`.
May be specified multiple times.

###### --consumer-version-selector

You can also retrieve pacts with consumer version selector, a more flexible approach in specifying which pacts you need.
May be specified multiple times. Read more about selectors [here](https://docs.pact.io/pact_broker/advanced_topics/consumer_version_selectors/).

###### --provider-version-tag

Tag to apply to the provider application version. May be specified multiple times.

###### --custom-provider-header

Header to add to provider state set up and pact verification requests e.g.`Authorization: Basic cGFjdDpwYWN0`
May be specified multiple times.

###### -t, --timeout

The duration in seconds we should wait to confirm that the verification process was successful. Defaults to 30.

###### -a, --provider-app-version

The provider application version. Required for publishing verification results.

###### -r, --publish-verification-results

Publish verification results to the broker.

### Python API
You can use the Verifier class. This has all the same parameters as the cli tool but allows you to write native python code and the test framework of your choice.

Expand Down
2 changes: 1 addition & 1 deletion RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

1. Increment the version according to semantic versioning rules in `pact/__version__.py`

2. To upgrade the the versions of `pact-mock_service` and `pact-provider-verifier`, change the
2. To upgrade the versions of `pact-mock_service` and `pact-provider-verifier`, change the
`PACT_STANDALONE_VERSION` in `setup.py` to match the latest version available from the
[pact-ruby-standalone](https://github.com/pact-foundation/pact-ruby-standalone/releases) repository.

Expand Down
35 changes: 22 additions & 13 deletions pact/cli/verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,26 @@
@click.option(
'username', '--pact-broker-username',
envvar='PACT_BROKER_USERNAME',
help='Username for Pact Broker basic authentication.')
help='Username for Pact Broker basic authentication. Can also be specified'
' via the environment variable PACT_BROKER_USERNAME.')
@click.option(
'broker_base_url', '--pact-broker-url',
default='',
envvar='PACT_BROKER_BASE_URL',
help='Base URl for the Pact Broker instance to publish pacts to.')
help='Base URl for the Pact Broker instance to publish pacts to. Can also be specified'
' via the environment variable PACT_BROKER_BASE_URL.')
@click.option(
'consumer_version_tag', '--consumer-version-tag',
default='',
multiple=True,
help='Retrieve the latest pacts with this consumer version tag. '
'Used in conjunction with --provider.')
'Used in conjunction with --provider. May be specified multiple times.')
@click.option(
'consumer_version_selector', '--consumer-version-selector',
default='',
multiple=True,
help='Retrieve the latest pacts with this consumer version selector. '
'Used in conjunction with --provider. May be specified multiple times.')
@click.option(
'provider_version_tag', '--provider-version-tag',
default='',
Expand All @@ -59,16 +67,16 @@
'password', '--pact-broker-password',
envvar='PACT_BROKER_PASSWORD',
help='Password for Pact Broker basic authentication. Can also be specified'
' via the environment variable PACT_BROKER_PASSWORD')
' via the environment variable PACT_BROKER_PASSWORD.')
@click.option(
'token', '--pact-broker-token',
envvar='PACT_BROKER_TOKEN',
help='Bearer token for Pact Broker authentication. Can also be specified'
' via the environment variable PACT_BROKER_TOKEN')
' via the environment variable PACT_BROKER_TOKEN.')
@click.option(
'provider', '--provider',
default='',
help='Retrieve the latest pacts for this provider')
help='Retrieve the latest pacts for this provider.')
@click.option(
'headers', '--custom-provider-header',
envvar='CUSTOM_PROVIDER_HEADER',
Expand All @@ -80,17 +88,17 @@
@click.option(
'timeout', '-t', '--timeout',
default=30,
help='The duration in seconds we should wait to confirm verification'
help='The duration in seconds we should wait to confirm that the verification'
' process was successful. Defaults to 30.',
type=int)
@click.option(
'provider_app_version', '-a', '--provider-app-version',
help='The provider application version, '
'required for publishing verification results')
help='The provider application version. '
'Required for publishing verification results.')
@click.option(
'publish_verification_results', '-r', '--publish-verification-results',
default=False,
help='Publish verification results to the broker',
help='Publish verification results to the broker.',
is_flag=True)
@click.option(
'--verbose/--no-verbose',
Expand All @@ -107,9 +115,9 @@
'log_level', '--log-level',
help='The logging level.')
def main(pacts, base_url, pact_url, pact_urls, states_url, states_setup_url,
username, broker_base_url, consumer_version_tag, provider_version_tag,
password, token, provider, headers, timeout, provider_app_version,
publish_verification_results, verbose, log_dir, log_level):
username, broker_base_url, consumer_version_tag, consumer_version_selector,
provider_version_tag, password, token, provider, headers, timeout,
provider_app_version, publish_verification_results, verbose, log_dir, log_level):
"""
Verify one or more contracts against a provider service.
Expand Down Expand Up @@ -162,6 +170,7 @@ def main(pacts, base_url, pact_url, pact_urls, states_url, states_setup_url,
'timeout': timeout,
'verbose': verbose,
'consumer_tags': list(consumer_version_tag),
'consumer_selectors': list(consumer_version_selector),
'provider_tags': list(provider_version_tag),
'provider_states_setup_url': states_setup_url
}
Expand Down
2 changes: 2 additions & 0 deletions pact/verify_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ def call_verify(self, *pacts, provider_base_url, provider, **kwargs):
command.extend(['{}={}'.format('--custom-provider-header', header)])
for tag in kwargs.get('consumer_tags', []):
command.extend(["--consumer-version-tag={}".format(tag)])
for tag in kwargs.get('consumer_selectors', []):
command.extend(["--consumer-version-selector={}".format(tag)])
for tag in kwargs.get('provider_tags', []):
command.extend(["--provider-version-tag={}".format(tag)])

Expand Down
4 changes: 4 additions & 0 deletions tests/cli/test_verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ def test_all_broker_options(self, mock_wrapper):
'--pact-broker-url=http://localhost/broker',
'--consumer-version-tag=prod',
'--consumer-version-tag=dev',
'--consumer-version-selector={"tag": "master", "latest": true}',
'--consumer-version-selector={"tag": "staging", "latest": true}',
'--provider-version-tag=dev',
'--provider-version-tag=qa',
'--provider-base-url=http://localhost',
Expand All @@ -284,6 +286,8 @@ def test_all_broker_options(self, mock_wrapper):
broker_token='token',
broker_url='http://localhost/broker',
consumer_tags=['prod', 'dev'],
consumer_selectors=['{"tag": "master", "latest": true}',
'{"tag": "staging", "latest": true}'],
provider_tags=['dev', 'qa'],
provider_app_version='1.2.3',
# custom_provider_header=['Authorization: Basic cGFj', 'CustomHeader: somevalue'],
Expand Down

0 comments on commit a594e22

Please sign in to comment.