Skip to content

Commit a594e22

Browse files
Merge pull request #170 from alecgerona/feat/consumer-version-selector
feat: consumer version selector
2 parents 06d1090 + 05c5e41 commit a594e22

File tree

5 files changed

+67
-15
lines changed

5 files changed

+67
-15
lines changed

README.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,15 @@ requests.
347347

348348
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'}`.
349349

350+
###### --pact-broker-url
351+
352+
Base URl for the Pact Broker instance to publish pacts to. Can also be specified via the environment variable
353+
`PACT_BROKER_BASE_URL`.
354+
350355
###### --pact-broker-username
351356

352-
The username to use when contacting the Pact Broker.
357+
The username to use when contacting the Pact Broker. Can also be specified via the environment variable
358+
`PACT_BROKER_USERNAME`.
353359

354360
###### --pact-broker-password
355361

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

370+
###### --consumer-version-tag
371+
372+
Retrieve the latest pacts with this consumer version tag. Used in conjunction with `--provider`.
373+
May be specified multiple times.
374+
375+
###### --consumer-version-selector
376+
377+
You can also retrieve pacts with consumer version selector, a more flexible approach in specifying which pacts you need.
378+
May be specified multiple times. Read more about selectors [here](https://docs.pact.io/pact_broker/advanced_topics/consumer_version_selectors/).
379+
380+
###### --provider-version-tag
381+
382+
Tag to apply to the provider application version. May be specified multiple times.
383+
384+
###### --custom-provider-header
385+
386+
Header to add to provider state set up and pact verification requests e.g.`Authorization: Basic cGFjdDpwYWN0`
387+
May be specified multiple times.
388+
389+
###### -t, --timeout
390+
391+
The duration in seconds we should wait to confirm that the verification process was successful. Defaults to 30.
392+
393+
###### -a, --provider-app-version
394+
395+
The provider application version. Required for publishing verification results.
396+
397+
###### -r, --publish-verification-results
398+
399+
Publish verification results to the broker.
400+
364401
### Python API
365402
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.
366403

RELEASING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

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

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

pact/cli/verify.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,26 @@
3737
@click.option(
3838
'username', '--pact-broker-username',
3939
envvar='PACT_BROKER_USERNAME',
40-
help='Username for Pact Broker basic authentication.')
40+
help='Username for Pact Broker basic authentication. Can also be specified'
41+
' via the environment variable PACT_BROKER_USERNAME.')
4142
@click.option(
4243
'broker_base_url', '--pact-broker-url',
4344
default='',
4445
envvar='PACT_BROKER_BASE_URL',
45-
help='Base URl for the Pact Broker instance to publish pacts to.')
46+
help='Base URl for the Pact Broker instance to publish pacts to. Can also be specified'
47+
' via the environment variable PACT_BROKER_BASE_URL.')
4648
@click.option(
4749
'consumer_version_tag', '--consumer-version-tag',
4850
default='',
4951
multiple=True,
5052
help='Retrieve the latest pacts with this consumer version tag. '
51-
'Used in conjunction with --provider.')
53+
'Used in conjunction with --provider. May be specified multiple times.')
54+
@click.option(
55+
'consumer_version_selector', '--consumer-version-selector',
56+
default='',
57+
multiple=True,
58+
help='Retrieve the latest pacts with this consumer version selector. '
59+
'Used in conjunction with --provider. May be specified multiple times.')
5260
@click.option(
5361
'provider_version_tag', '--provider-version-tag',
5462
default='',
@@ -59,16 +67,16 @@
5967
'password', '--pact-broker-password',
6068
envvar='PACT_BROKER_PASSWORD',
6169
help='Password for Pact Broker basic authentication. Can also be specified'
62-
' via the environment variable PACT_BROKER_PASSWORD')
70+
' via the environment variable PACT_BROKER_PASSWORD.')
6371
@click.option(
6472
'token', '--pact-broker-token',
6573
envvar='PACT_BROKER_TOKEN',
6674
help='Bearer token for Pact Broker authentication. Can also be specified'
67-
' via the environment variable PACT_BROKER_TOKEN')
75+
' via the environment variable PACT_BROKER_TOKEN.')
6876
@click.option(
6977
'provider', '--provider',
7078
default='',
71-
help='Retrieve the latest pacts for this provider')
79+
help='Retrieve the latest pacts for this provider.')
7280
@click.option(
7381
'headers', '--custom-provider-header',
7482
envvar='CUSTOM_PROVIDER_HEADER',
@@ -80,17 +88,17 @@
8088
@click.option(
8189
'timeout', '-t', '--timeout',
8290
default=30,
83-
help='The duration in seconds we should wait to confirm verification'
91+
help='The duration in seconds we should wait to confirm that the verification'
8492
' process was successful. Defaults to 30.',
8593
type=int)
8694
@click.option(
8795
'provider_app_version', '-a', '--provider-app-version',
88-
help='The provider application version, '
89-
'required for publishing verification results')
96+
help='The provider application version. '
97+
'Required for publishing verification results.')
9098
@click.option(
9199
'publish_verification_results', '-r', '--publish-verification-results',
92100
default=False,
93-
help='Publish verification results to the broker',
101+
help='Publish verification results to the broker.',
94102
is_flag=True)
95103
@click.option(
96104
'--verbose/--no-verbose',
@@ -107,9 +115,9 @@
107115
'log_level', '--log-level',
108116
help='The logging level.')
109117
def main(pacts, base_url, pact_url, pact_urls, states_url, states_setup_url,
110-
username, broker_base_url, consumer_version_tag, provider_version_tag,
111-
password, token, provider, headers, timeout, provider_app_version,
112-
publish_verification_results, verbose, log_dir, log_level):
118+
username, broker_base_url, consumer_version_tag, consumer_version_selector,
119+
provider_version_tag, password, token, provider, headers, timeout,
120+
provider_app_version, publish_verification_results, verbose, log_dir, log_level):
113121
"""
114122
Verify one or more contracts against a provider service.
115123
@@ -162,6 +170,7 @@ def main(pacts, base_url, pact_url, pact_urls, states_url, states_setup_url,
162170
'timeout': timeout,
163171
'verbose': verbose,
164172
'consumer_tags': list(consumer_version_tag),
173+
'consumer_selectors': list(consumer_version_selector),
165174
'provider_tags': list(provider_version_tag),
166175
'provider_states_setup_url': states_setup_url
167176
}

pact/verify_wrapper.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ def call_verify(self, *pacts, provider_base_url, provider, **kwargs):
175175
command.extend(['{}={}'.format('--custom-provider-header', header)])
176176
for tag in kwargs.get('consumer_tags', []):
177177
command.extend(["--consumer-version-tag={}".format(tag)])
178+
for tag in kwargs.get('consumer_selectors', []):
179+
command.extend(["--consumer-version-selector={}".format(tag)])
178180
for tag in kwargs.get('provider_tags', []):
179181
command.extend(["--provider-version-tag={}".format(tag)])
180182

tests/cli/test_verify.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ def test_all_broker_options(self, mock_wrapper):
259259
'--pact-broker-url=http://localhost/broker',
260260
'--consumer-version-tag=prod',
261261
'--consumer-version-tag=dev',
262+
'--consumer-version-selector={"tag": "master", "latest": true}',
263+
'--consumer-version-selector={"tag": "staging", "latest": true}',
262264
'--provider-version-tag=dev',
263265
'--provider-version-tag=qa',
264266
'--provider-base-url=http://localhost',
@@ -284,6 +286,8 @@ def test_all_broker_options(self, mock_wrapper):
284286
broker_token='token',
285287
broker_url='http://localhost/broker',
286288
consumer_tags=['prod', 'dev'],
289+
consumer_selectors=['{"tag": "master", "latest": true}',
290+
'{"tag": "staging", "latest": true}'],
287291
provider_tags=['dev', 'qa'],
288292
provider_app_version='1.2.3',
289293
# custom_provider_header=['Authorization: Basic cGFj', 'CustomHeader: somevalue'],

0 commit comments

Comments
 (0)