Skip to content

Commit 89733d6

Browse files
authored
feat: Support verify with branch (#302)
* feat: support verify with provider branch * chore: update lint setting * chore: cleanup * chore: update readme verifier section
1 parent 42e0db8 commit 89733d6

File tree

6 files changed

+24
-5
lines changed

6 files changed

+24
-5
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,10 @@ May be specified multiple times. Read more about selectors [here](https://docs.p
381381

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

384+
###### --provider-version-branch
385+
386+
Branch to apply to the provider application version.
387+
384388
###### --custom-provider-header
385389

386390
Header to add to provider state set up and pact verification requests e.g.`Authorization: Basic cGFjdDpwYWN0`

pact/cli/verify.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@
6363
multiple=True,
6464
help='Tag to apply to the provider application version. '
6565
'May be specified multiple times.')
66+
@click.option(
67+
'provider_version_branch', '--provider-version-branch',
68+
default='',
69+
help='The name of the branch the provider version belongs to.')
6670
@click.option(
6771
'password', '--pact-broker-password',
6872
envvar='PACT_BROKER_PASSWORD',
@@ -125,7 +129,7 @@ def main(pacts, base_url, pact_url, pact_urls, states_url, states_setup_url,
125129
username, broker_base_url, consumer_version_tag, consumer_version_selector,
126130
provider_version_tag, password, token, provider, headers, timeout,
127131
provider_app_version, publish_verification_results, verbose, log_dir,
128-
log_level, enable_pending, include_wip_pacts_since):
132+
log_level, enable_pending, include_wip_pacts_since, provider_version_branch):
129133
"""
130134
Verify one or more contracts against a provider service.
131135
@@ -181,6 +185,7 @@ def main(pacts, base_url, pact_url, pact_urls, states_url, states_setup_url,
181185
'consumer_tags': list(consumer_version_tag),
182186
'consumer_selectors': list(consumer_version_selector),
183187
'provider_tags': list(provider_version_tag),
188+
'provider_version_branch': provider_version_branch,
184189
'provider_states_setup_url': states_setup_url,
185190
}
186191

pact/verifier.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ def extract_params(self, **kwargs):
108108
publish_verification_results = kwargs.get('publish_verification_results', None)
109109
raw_consumer_selectors = kwargs.get('consumer_version_selectors', [])
110110
consumer_selectors = self._build_consumer_selectors(raw_consumer_selectors)
111+
provider_version_branch = kwargs.get('provider_version_branch')
111112

112113
options = {
113114
'log_dir': log_dir,
@@ -121,7 +122,8 @@ def extract_params(self, **kwargs):
121122
'verbose': verbose,
122123
'provider_app_version': provider_app_version,
123124
'consumer_selectors': consumer_selectors,
124-
'publish_verification_results': publish_verification_results
125+
'publish_verification_results': publish_verification_results,
126+
'provider_version_branch': provider_version_branch
125127
}
126128
return self.filter_empty_options(**options)
127129

pact/verify_wrapper.py

+4
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ def call_verify(
143143
self._validate_input(pacts, **kwargs)
144144

145145
provider_app_version = kwargs.get('provider_app_version')
146+
provider_version_branch = kwargs.get('provider_version_branch')
146147
options = {
147148
'--provider-base-url': provider_base_url,
148149
'--provider': provider,
@@ -180,6 +181,9 @@ def call_verify(
180181
if include_wip_pacts_since:
181182
command.extend(['--include-wip-pacts-since={}'.format(include_wip_pacts_since)])
182183

184+
if provider_version_branch:
185+
command.extend(["--provider-version-branch={}".format(provider_version_branch)])
186+
183187
headers = kwargs.get('custom_provider_headers', [])
184188
for header in headers:
185189
command.extend(['{}={}'.format('--custom-provider-header', header)])

tests/cli/test_verify.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ def test_all_broker_options(self, mock_wrapper):
294294
'--verbose',
295295
'--enable-pending',
296296
'--include-wip-pacts-since=2018-01-01',
297+
'--provider-version-branch=provider-branch'
297298
])
298299

299300
self.assertEqual(result.exit_code, 0, result.output)
@@ -315,7 +316,8 @@ def test_all_broker_options(self, mock_wrapper):
315316
timeout=60,
316317
verbose=True,
317318
enable_pending=True,
318-
include_wip_pacts_since='2018-01-01')
319+
include_wip_pacts_since='2018-01-01',
320+
provider_version_branch='provider-branch')
319321

320322
@patch("pact.verify_wrapper.isfile", return_value=True)
321323
def test_publishing_missing_version(self, mock_isfile):

tests/test_verify_wrapper.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ def setUp(self):
5555
'--consumer-version-tag=dev',
5656
'--no-enable-pending',
5757
'--provider-version-tag=dev',
58-
'--provider-version-tag=qa']
58+
'--provider-version-tag=qa',
59+
'--provider-version-branch=provider-branch']
5960

6061
def assertProcess(self, *expected):
6162
self.assertEqual(self.mock_Popen.call_count, 1)
@@ -154,7 +155,8 @@ def test_uses_broker_if_no_pacts_and_provider_required(self):
154155
broker_token='token',
155156
broker_url='http://broker',
156157
consumer_tags=['prod', 'dev'],
157-
provider_tags=['dev', 'qa'])
158+
provider_tags=['dev', 'qa'],
159+
provider_version_branch='provider-branch')
158160

159161
self.assertProcess(*self.broker_call)
160162
self.assertEqual(result, 0)

0 commit comments

Comments
 (0)