Skip to content

Commit 17aa15b

Browse files
committed
Issue: Cannot supply multiple files to pact-verifier
- Updated '--pact-urls' to be a single comma separated string argument - Added '--pact-url' which can be specified multiple times
1 parent 65b493d commit 17aa15b

File tree

5 files changed

+52
-17
lines changed

5 files changed

+52
-17
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ local_settings.py
6161
instance/
6262
.webassets-cache
6363

64+
# Intellij stuff
65+
.idea/
66+
6467
# Scrapy stuff:
6568
.scrapy
6669

README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ The simplest example is verifying a server with locally stored Pact files and no
222222
states:
223223

224224
```bash
225-
pact-verifier --provider-base-url=http://localhost:8080 --pact-urls=./pacts/consumer-provider.json
225+
pact-verifier --provider-base-url=http://localhost:8080 --pact-url=./pacts/consumer-provider.json
226226
```
227227

228228
Which will immediately invoke the Pact verifier, making HTTP requests to the server located
@@ -235,10 +235,20 @@ There are several options for configuring how the Pacts are verified:
235235

236236
Required. Defines the URL of the server to make requests to when verifying the Pacts.
237237

238+
###### --pact-url
239+
240+
Required if --pact-urls not specified. The location of a Pact file you want
241+
to verify. This can be a URL to a [Pact Broker] or a local path, to provide
242+
multiple files, specify multiple arguments.
243+
244+
```
245+
pact-verifier --provider-base-url=http://localhost:8080 --pact-url=./pacts/one.json --pact-url=./pacts/two.json
246+
```
247+
238248
###### --pact-urls
239249

240-
Required. The location of the Pact files you want to verify. This can be a URL to a [Pact Broker]
241-
or one or more local paths, separated by a comma.
250+
Required if --pact-url not specified. The location of the Pact files you want
251+
to verify. This can be a URL to a [Pact Broker] or one or more local paths, separated by a comma.
242252

243253
###### --provider-states-url
244254

pact/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""Pact version info."""
22

3-
__version__ = '0.6.2'
3+
__version__ = '0.7.0'

pact/test/test_verify.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,14 @@ def setUp(self):
3737
self.runner = CliRunner()
3838
self.default_call = [
3939
'--provider-base-url=http://localhost',
40-
'--pact-urls=./pacts/consumer-provider.json']
40+
'--pact-urls=./pacts/consumer-provider.json,'
41+
'./pacts/consumer-provider2.json,./pacts/consumer-provider3.json']
4142

4243
self.default_opts = [
4344
'--provider-base-url=http://localhost',
44-
'--pact-urls=./pacts/consumer-provider.json']
45+
'--pact-url=./pacts/consumer-provider.json',
46+
'--pact-urls=./pacts/consumer-provider2.json,'
47+
'./pacts/consumer-provider3.json']
4548

4649
def assertProcess(self, *expected):
4750
self.assertEqual(self.mock_Popen.call_count, 1)
@@ -59,8 +62,9 @@ def test_provider_base_url_is_required(self):
5962
def test_pact_urls_are_required(self):
6063
result = self.runner.invoke(
6164
verify.main, ['--provider-base-url=http://localhost'])
62-
self.assertEqual(result.exit_code, 2)
63-
self.assertIn(b'--pact-urls', result.output_bytes)
65+
print(result)
66+
self.assertEqual(result.exit_code, 1)
67+
self.assertIn(b'--pact-url or --pact-urls', result.output_bytes)
6468
self.assertFalse(self.mock_Popen.called)
6569

6670
def test_local_pact_urls_must_exist(self):
@@ -121,7 +125,10 @@ def test_all_options(self):
121125
self.mock_Popen.return_value.returncode = 0
122126
result = self.runner.invoke(verify.main, [
123127
'--provider-base-url=http://localhost',
124-
'--pact-urls=./pacts/consumer-provider.json',
128+
'--pact-urls=./pacts/consumer-provider.json,'
129+
'./pacts/consumer-provider2.json',
130+
'--pact-url=./pacts/consumer-provider3.json',
131+
'--pact-url=./pacts/consumer-provider4.json',
125132
'--provider-states-url=http=//localhost/provider-states',
126133
'--provider-states-setup-url=http://localhost/provider-states/set',
127134
'--pact-broker-username=user',
@@ -132,7 +139,9 @@ def test_all_options(self):
132139
self.assertEqual(self.mock_Popen.call_count, 1)
133140
self.assertProcess(
134141
'--provider-base-url=http://localhost',
135-
'--pact-urls=./pacts/consumer-provider.json',
142+
'--pact-urls=./pacts/consumer-provider3.json,'
143+
'./pacts/consumer-provider4.json,'
144+
'./pacts/consumer-provider.json,./pacts/consumer-provider2.json',
136145
'--provider-states-url=http=//localhost/provider-states',
137146
'--provider-states-setup-url=http://localhost/provider-states/set',
138147
'--broker-username=user',

pact/verify.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,17 @@
1818
help='Base URL of the provider to verify against.',
1919
required=True)
2020
@click.option(
21-
'pact_urls', '--pact-urls',
21+
'pact_url', '--pact-url',
2222
help='The URI of the pact to verify.'
2323
' Can be an HTTP URI or a local file path.'
2424
' It can be specified multiple times to verify several pacts.',
25-
multiple=True,
26-
required=True)
25+
multiple=True)
26+
@click.option(
27+
'pact_urls', '--pact-urls',
28+
default='',
29+
help='The URI(s) of the pact to verify.'
30+
' Can be an HTTP URI(s) or local file path(s).'
31+
' Provide multiple URI separated by a comma.')
2732
@click.option(
2833
'states_url', '--provider-states-url',
2934
help='URL to fetch the provider states for the given provider API.')
@@ -44,14 +49,14 @@
4449
help='The duration in seconds we should wait to confirm verification'
4550
' process was successful. Defaults to 30.',
4651
type=int)
47-
def main(base_url, pact_urls, states_url, states_setup_url, username,
52+
def main(base_url, pact_url, pact_urls, states_url, states_setup_url, username,
4853
password, timeout):
4954
"""
5055
Verify one or more contracts against a provider service.
5156
5257
Minimal example:
5358
54-
pact-verifier --provider-base-url=http://localhost:8080 --pact-urls=./pacts
59+
pact-verifier --provider-base-url=http://localhost:8080 --pact-url=./pact
5560
""" # NOQA
5661
error = click.style('Error:', fg='red')
5762
if bool(states_url) != bool(states_setup_url):
@@ -61,7 +66,15 @@ def main(base_url, pact_urls, states_url, states_setup_url, username,
6166
' --provider-states-url and --provider-states-setup-url.')
6267
raise click.Abort()
6368

64-
missing_files = [path for path in pact_urls if not path_exists(path)]
69+
all_pact_urls = list(pact_url)
70+
all_pact_urls.extend(p for p in pact_urls.split(',') if p)
71+
if not all_pact_urls:
72+
click.echo(
73+
error
74+
+ ' At least one of --pact-url or --pact-urls is required.')
75+
raise click.Abort()
76+
77+
missing_files = [path for path in all_pact_urls if not path_exists(path)]
6578
if missing_files:
6679
click.echo(
6780
error
@@ -71,7 +84,7 @@ def main(base_url, pact_urls, states_url, states_setup_url, username,
7184

7285
options = {
7386
'--provider-base-url': base_url,
74-
'--pact-urls': ','.join(pact_urls),
87+
'--pact-urls': ','.join(all_pact_urls),
7588
'--provider-states-url': states_url,
7689
'--provider-states-setup-url': states_setup_url,
7790
'--broker-username': username,

0 commit comments

Comments
 (0)