Skip to content

Commit 223ea76

Browse files
Merge pull request #32 from SimKev2/pacturls
Issue: Cannot supply multiple files to pact-verifier
2 parents e382eb4 + b6e1a8b commit 223ea76

File tree

5 files changed

+82
-17
lines changed

5 files changed

+82
-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: 34 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,14 +139,35 @@ 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',
139148
'--broker-password=pass')
140149
self.mock_Popen.return_value.communicate.assert_called_once_with(
141150
timeout=60)
142151

152+
def test_deprecated_pact_urls(self):
153+
self.mock_Popen.return_value.returncode = 0
154+
result = self.runner.invoke(verify.main, [
155+
'--provider-base-url=http://localhost',
156+
'--pact-urls=./pacts/consumer-provider.json',
157+
'--pact-urls=./pacts/consumer-provider2.json'
158+
])
159+
self.assertEqual(result.exit_code, 0)
160+
self.assertIn(
161+
b'Multiple --pact-urls arguments are deprecated.',
162+
result.output_bytes)
163+
self.assertEqual(self.mock_Popen.call_count, 1)
164+
self.assertProcess(
165+
'--provider-base-url=http://localhost',
166+
'--pact-urls=./pacts/consumer-provider.json,'
167+
'./pacts/consumer-provider2.json')
168+
self.mock_Popen.return_value.communicate.assert_called_once_with(
169+
timeout=30)
170+
143171

144172
class path_existsTestCase(TestCase):
145173
def setUp(self):

pact/verify.py

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,18 @@
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.',
32+
multiple=True) # Remove in major version 1.0.0
2733
@click.option(
2834
'states_url', '--provider-states-url',
2935
help='URL to fetch the provider states for the given provider API.')
@@ -44,24 +50,42 @@
4450
help='The duration in seconds we should wait to confirm verification'
4551
' process was successful. Defaults to 30.',
4652
type=int)
47-
def main(base_url, pact_urls, states_url, states_setup_url, username,
53+
def main(base_url, pact_url, pact_urls, states_url, states_setup_url, username,
4854
password, timeout):
4955
"""
5056
Verify one or more contracts against a provider service.
5157
5258
Minimal example:
5359
54-
pact-verifier --provider-base-url=http://localhost:8080 --pact-urls=./pacts
60+
pact-verifier --provider-base-url=http://localhost:8080 --pact-url=./pact
5561
""" # NOQA
5662
error = click.style('Error:', fg='red')
63+
warning = click.style('Warning:', fg='yellow')
5764
if bool(states_url) != bool(states_setup_url):
5865
click.echo(
5966
error
6067
+ ' To use provider states you must provide both'
6168
' --provider-states-url and --provider-states-setup-url.')
6269
raise click.Abort()
6370

64-
missing_files = [path for path in pact_urls if not path_exists(path)]
71+
all_pact_urls = list(pact_url)
72+
for urls in pact_urls: # Remove in major version 1.0.0
73+
all_pact_urls.extend(p for p in urls.split(',') if p)
74+
75+
if len(pact_urls) > 1:
76+
click.echo(
77+
warning
78+
+ ' Multiple --pact-urls arguments are deprecated. '
79+
'Please provide a comma separated list of pacts to --pact-urls, '
80+
'or multiple --pact-url arguments.')
81+
82+
if not all_pact_urls:
83+
click.echo(
84+
error
85+
+ ' At least one of --pact-url or --pact-urls is required.')
86+
raise click.Abort()
87+
88+
missing_files = [path for path in all_pact_urls if not path_exists(path)]
6589
if missing_files:
6690
click.echo(
6791
error
@@ -71,7 +95,7 @@ def main(base_url, pact_urls, states_url, states_setup_url, username,
7195

7296
options = {
7397
'--provider-base-url': base_url,
74-
'--pact-urls': ','.join(pact_urls),
98+
'--pact-urls': ','.join(all_pact_urls),
7599
'--provider-states-url': states_url,
76100
'--provider-states-setup-url': states_setup_url,
77101
'--broker-username': username,

0 commit comments

Comments
 (0)