pact_broker-client 0.0.6 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +12 -0
  3. data/Gemfile.lock +57 -32
  4. data/README.md +47 -0
  5. data/doc/markdown/Pact Broker Client - Pact Broker.md +582 -0
  6. data/doc/markdown/README.md +3 -0
  7. data/lib/pact_broker/client/base_client.rb +3 -1
  8. data/lib/pact_broker/client/pact_broker_client.rb +4 -3
  9. data/lib/pact_broker/client/pacticipants.rb +1 -1
  10. data/lib/pact_broker/client/pacts.rb +22 -6
  11. data/lib/pact_broker/client/publish_pacts.rb +16 -6
  12. data/lib/pact_broker/client/retry.rb +26 -0
  13. data/lib/pact_broker/client/tasks/publication_task.rb +3 -2
  14. data/lib/pact_broker/client/version.rb +1 -1
  15. data/lib/pact_broker/client/versions.rb +1 -1
  16. data/spec/lib/pact_broker/client/base_client_spec.rb +51 -0
  17. data/spec/lib/pact_broker/client/pact_broker_client_spec.rb +28 -1
  18. data/spec/lib/pact_broker/client/pacticipants_spec.rb +18 -0
  19. data/spec/lib/pact_broker/client/publish_pacts_spec.rb +67 -5
  20. data/spec/lib/pact_broker/client/tasks/publication_task_spec.rb +4 -2
  21. data/spec/lib/pact_broker/client/versions_spec.rb +18 -0
  22. data/spec/pacts/pact_broker_client-pact_broker.json +87 -91
  23. data/spec/service_providers/pact_broker_client_pacticipant_version_spec.rb +56 -0
  24. data/spec/service_providers/pact_broker_client_publish_spec.rb +34 -12
  25. data/spec/service_providers/pact_broker_client_register_repository_spec.rb +2 -2
  26. data/spec/service_providers/pact_broker_client_retrive_pact_spec.rb +4 -47
  27. data/spec/service_providers/pact_broker_client_tags_spec.rb +3 -3
  28. data/spec/support/pacticipant_get.json +3 -3
  29. data/spec/support/pacticipants_list.json +1 -1
  30. data/spec/support/pacts_latest_list.json +2 -2
  31. metadata +34 -45
@@ -30,7 +30,7 @@ module PactBroker::Client
30
30
 
31
31
  context "when pacts are succesfully published" do
32
32
  it "invokes PublishPacts with the default values" do
33
- PactBroker::Client::PublishPacts.should_receive(:new).with('http://pact-broker', pact_file_list, '1.2.3').and_return(publish_pacts)
33
+ PactBroker::Client::PublishPacts.should_receive(:new).with('http://pact-broker', pact_file_list, '1.2.3', {}).and_return(publish_pacts)
34
34
  publish_pacts.should_receive(:call).and_return(true)
35
35
  Rake::Task['pact:publish'].execute
36
36
  end
@@ -50,17 +50,19 @@ module PactBroker::Client
50
50
  before :all do
51
51
  @pact_broker_base_url = "http://some-host"
52
52
  @pattern = "pact/*.json"
53
+ @pact_broker_basic_auth = { username: 'user', password: 'pass'}
53
54
  PactBroker::Client::PublicationTask.new(:custom) do | task |
54
55
  task.consumer_version = '1.2.3'
55
56
  task.pact_broker_base_url = @pact_broker_base_url
56
57
  task.pattern = @pattern
58
+ task.pact_broker_basic_auth = @pact_broker_basic_auth
57
59
  end
58
60
  end
59
61
 
60
62
  let(:pattern) { @pattern }
61
63
 
62
64
  it "invokes PublishPacts with the customised values" do
63
- PactBroker::Client::PublishPacts.should_receive(:new).with(@pact_broker_base_url, pact_file_list, '1.2.3')
65
+ PactBroker::Client::PublishPacts.should_receive(:new).with(@pact_broker_base_url, pact_file_list, '1.2.3', {basic_auth: @pact_broker_basic_auth})
64
66
  publish_pacts.should_receive(:call).and_return(true)
65
67
  Rake::Task['pact:publish:custom'].execute
66
68
  end
@@ -0,0 +1,18 @@
1
+ require 'pact_broker/client/versions'
2
+ module PactBroker
3
+ module Client
4
+ describe Versions do
5
+ let(:client_options) do
6
+ { some_option: 'option value'}
7
+ end
8
+ let(:base_url) { 'https://blah' }
9
+
10
+ describe 'pacts' do
11
+ it 'initializes versions with base url and client options' do
12
+ expect(PactBroker::Client::Pacts).to receive(:new).with(base_url: base_url, client_options: client_options)
13
+ Versions.new(base_url: base_url, client_options: client_options).pacts
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,10 +1,10 @@
1
1
  {
2
- "provider": {
3
- "name": "Pact Broker"
4
- },
5
2
  "consumer": {
6
3
  "name": "Pact Broker Client"
7
4
  },
5
+ "provider": {
6
+ "name": "Pact Broker"
7
+ },
8
8
  "interactions": [
9
9
  {
10
10
  "description": "a request to list the latest pacts",
@@ -16,10 +16,10 @@
16
16
  }
17
17
  },
18
18
  "response": {
19
+ "status": 200,
19
20
  "headers": {
20
21
  "Content-Type": "application/hal+json"
21
22
  },
22
- "status": 200,
23
23
  "body": {
24
24
  "_links": {
25
25
  "self": {
@@ -31,10 +31,10 @@
31
31
  "_links": {
32
32
  "self": [
33
33
  {
34
- "href": "http://example.org/pact/provider/Pricing%20Service/consumer/Condor/latest"
34
+ "href": "http://example.org/pacts/provider/Pricing%20Service/consumer/Condor/latest"
35
35
  },
36
36
  {
37
- "href": "http://example.org/pact/provider/Pricing%20Service/consumer/Condor/version/1.3.0"
37
+ "href": "http://example.org/pacts/provider/Pricing%20Service/consumer/Condor/version/1.3.0"
38
38
  }
39
39
  ]
40
40
  },
@@ -76,10 +76,10 @@
76
76
  }
77
77
  },
78
78
  "response": {
79
+ "status": 200,
79
80
  "headers": {
80
81
  "Content-Type": "application/hal+json"
81
82
  },
82
- "status": 200,
83
83
  "body": {
84
84
  "_links": {
85
85
  "self": {
@@ -101,7 +101,7 @@
101
101
  },
102
102
  "name": "Condor",
103
103
  "_embedded": {
104
- "latest_version": {
104
+ "latest-version": {
105
105
  "_links": {
106
106
  "self": {
107
107
  "href": "http://example.org/pacticipants/Condor/versions/1.3.0"
@@ -125,10 +125,10 @@
125
125
  }
126
126
  },
127
127
  "response": {
128
+ "status": 200,
128
129
  "headers": {
129
130
  "Content-Type": "application/hal+json"
130
131
  },
131
- "status": 200,
132
132
  "body": {
133
133
  "_links": {
134
134
  "self": {
@@ -137,14 +137,14 @@
137
137
  "versions": {
138
138
  "href": "http://example.org/pacticipants/Pricing%20Service/versions"
139
139
  },
140
- "latest_version": {
140
+ "latest-version": {
141
141
  "href": "http://example.org/pacticipants/Pricing%20Service/versions/latest"
142
142
  }
143
143
  },
144
144
  "name": "Pricing Service",
145
- "repository_url": "git@git.realestate.com.au:business-systems/pricing-service",
145
+ "repositoryUrl": "git@git.realestate.com.au:business-systems/pricing-service",
146
146
  "_embedded": {
147
- "latest_version": {
147
+ "latest-version": {
148
148
  "_links": {
149
149
  "self": {
150
150
  "href": "http://example.org/pacticipants/Pricing%20Service/versions/1.3.0"
@@ -166,7 +166,9 @@
166
166
  }
167
167
  },
168
168
  "response": {
169
- "status": 404
169
+ "status": 404,
170
+ "headers": {
171
+ }
170
172
  }
171
173
  },
172
174
  {
@@ -174,7 +176,10 @@
174
176
  "provider_state": "the 'Pricing Service' already exists in the pact-broker",
175
177
  "request": {
176
178
  "method": "put",
177
- "path": "/pact/provider/Pricing%20Service/consumer/Condor/version/1.3.0",
179
+ "path": "/pacts/provider/Pricing%20Service/consumer/Condor/version/1.3.0",
180
+ "headers": {
181
+ "Content-Type": "application/json"
182
+ },
178
183
  "body": {
179
184
  "consumer": {
180
185
  "name": "Condor"
@@ -185,15 +190,19 @@
185
190
  "interactions": [
186
191
 
187
192
  ]
188
- },
189
- "headers": {
190
- "Content-Type": "application/json"
191
193
  }
192
194
  },
193
195
  "response": {
196
+ "status": 201,
194
197
  "headers": {
195
198
  },
196
- "status": 201
199
+ "body": {
200
+ "_links": {
201
+ "pb:latest-pact-version": {
202
+ "href": "http://example.org/pacts/provider/Pricing%20Service/consumer/Condor/latest"
203
+ }
204
+ }
205
+ }
197
206
  }
198
207
  },
199
208
  {
@@ -201,7 +210,10 @@
201
210
  "provider_state": "the 'Pricing Service' and 'Condor' already exist in the pact-broker, and Condor already has a pact published for version 1.3.0",
202
211
  "request": {
203
212
  "method": "put",
204
- "path": "/pact/provider/Pricing%20Service/consumer/Condor/version/1.3.0",
213
+ "path": "/pacts/provider/Pricing%20Service/consumer/Condor/version/1.3.0",
214
+ "headers": {
215
+ "Content-Type": "application/json"
216
+ },
205
217
  "body": {
206
218
  "consumer": {
207
219
  "name": "Condor"
@@ -212,15 +224,19 @@
212
224
  "interactions": [
213
225
 
214
226
  ]
215
- },
216
- "headers": {
217
- "Content-Type": "application/json"
218
227
  }
219
228
  },
220
229
  "response": {
230
+ "status": 200,
221
231
  "headers": {
222
232
  },
223
- "status": 200
233
+ "body": {
234
+ "_links": {
235
+ "pb:latest-pact-version": {
236
+ "href": "http://example.org/pacts/provider/Pricing%20Service/consumer/Condor/latest"
237
+ }
238
+ }
239
+ }
224
240
  }
225
241
  },
226
242
  {
@@ -228,7 +244,10 @@
228
244
  "provider_state": "'Condor' already exist in the pact-broker, but the 'Pricing Service' does not",
229
245
  "request": {
230
246
  "method": "put",
231
- "path": "/pact/provider/Pricing%20Service/consumer/Condor/version/1.3.0",
247
+ "path": "/pacts/provider/Pricing%20Service/consumer/Condor/version/1.3.0",
248
+ "headers": {
249
+ "Content-Type": "application/json"
250
+ },
232
251
  "body": {
233
252
  "consumer": {
234
253
  "name": "Condor"
@@ -239,15 +258,19 @@
239
258
  "interactions": [
240
259
 
241
260
  ]
242
- },
243
- "headers": {
244
- "Content-Type": "application/json"
245
261
  }
246
262
  },
247
263
  "response": {
264
+ "status": 201,
248
265
  "headers": {
249
266
  },
250
- "status": 201
267
+ "body": {
268
+ "_links": {
269
+ "pb:latest-pact-version": {
270
+ "href": "http://example.org/pacts/provider/Pricing%20Service/consumer/Condor/latest"
271
+ }
272
+ }
273
+ }
251
274
  }
252
275
  },
253
276
  {
@@ -255,7 +278,10 @@
255
278
  "provider_state": "an error occurs while publishing a pact",
256
279
  "request": {
257
280
  "method": "put",
258
- "path": "/pact/provider/Pricing%20Service/consumer/Condor/version/1.3.0",
281
+ "path": "/pacts/provider/Pricing%20Service/consumer/Condor/version/1.3.0",
282
+ "headers": {
283
+ "Content-Type": "application/json"
284
+ },
259
285
  "body": {
260
286
  "consumer": {
261
287
  "name": "Condor"
@@ -266,9 +292,6 @@
266
292
  "interactions": [
267
293
 
268
294
  ]
269
- },
270
- "headers": {
271
- "Content-Type": "application/json"
272
295
  }
273
296
  },
274
297
  "response": {
@@ -281,7 +304,11 @@
281
304
  "json_class": "Pact::Term",
282
305
  "data": {
283
306
  "generate": "An error occurred",
284
- "matcher": {"json_class":"Regexp","o":0,"s":".*"}
307
+ "matcher": {
308
+ "json_class": "Regexp",
309
+ "o": 0,
310
+ "s": ".*"
311
+ }
285
312
  }
286
313
  }
287
314
  }
@@ -293,11 +320,11 @@
293
320
  "request": {
294
321
  "method": "patch",
295
322
  "path": "/pacticipants/Pricing%20Service",
296
- "body": {
297
- "repository_url": "git@git.realestate.com.au:business-systems/pricing-service"
298
- },
299
323
  "headers": {
300
324
  "Content-Type": "application/json"
325
+ },
326
+ "body": {
327
+ "repository_url": "git@git.realestate.com.au:business-systems/pricing-service"
301
328
  }
302
329
  },
303
330
  "response": {
@@ -312,11 +339,11 @@
312
339
  "request": {
313
340
  "method": "patch",
314
341
  "path": "/pacticipants/Pricing%20Service",
315
- "body": {
316
- "repository_url": "git@git.realestate.com.au:business-systems/pricing-service"
317
- },
318
342
  "headers": {
319
343
  "Content-Type": "application/json"
344
+ },
345
+ "body": {
346
+ "repository_url": "git@git.realestate.com.au:business-systems/pricing-service"
320
347
  }
321
348
  },
322
349
  "response": {
@@ -330,14 +357,14 @@
330
357
  "provider_state": "the 'Pricing Service' and 'Condor' already exist in the pact-broker, and Condor already has a pact published for version 1.3.0",
331
358
  "request": {
332
359
  "method": "get",
333
- "path": "/pact/provider/Pricing%20Service/consumer/Condor/version/1.3.0",
360
+ "path": "/pacts/provider/Pricing%20Service/consumer/Condor/version/1.3.0",
334
361
  "headers": {
335
362
  }
336
363
  },
337
364
  "response": {
365
+ "status": 200,
338
366
  "headers": {
339
367
  },
340
- "status": 200,
341
368
  "body": {
342
369
  "consumer": {
343
370
  "name": "Condor"
@@ -356,7 +383,7 @@
356
383
  "provider_state": "a pact between Condor and the Pricing Service exists",
357
384
  "request": {
358
385
  "method": "get",
359
- "path": "/pact/provider/Pricing%20Service/consumer/Condor/latest",
386
+ "path": "/pacts/provider/Pricing%20Service/consumer/Condor/latest",
360
387
  "headers": {
361
388
  }
362
389
  },
@@ -384,7 +411,7 @@
384
411
  "provider_state": "no pact between Condor and the Pricing Service exists",
385
412
  "request": {
386
413
  "method": "get",
387
- "path": "/pact/provider/Pricing%20Service/consumer/Condor/latest",
414
+ "path": "/pacts/provider/Pricing%20Service/consumer/Condor/latest",
388
415
  "headers": {
389
416
  }
390
417
  },
@@ -399,7 +426,7 @@
399
426
  "provider_state": "a pact between Condor and the Pricing Service exists for the production version of Condor",
400
427
  "request": {
401
428
  "method": "get",
402
- "path": "/pact/provider/Pricing%20Service/consumer/Condor/latest/prod",
429
+ "path": "/pacts/provider/Pricing%20Service/consumer/Condor/latest/prod",
403
430
  "headers": {
404
431
  "Accept": "application/json"
405
432
  }
@@ -421,47 +448,6 @@
421
448
  }
422
449
  }
423
450
  },
424
- {
425
- "description": "a request for the latest version tagged with 'prod'",
426
- "provider_state": "a version with production details exists for the Pricing Service",
427
- "request": {
428
- "method": "get",
429
- "path": "/pacticipants/Pricing%20Service/versions/latest",
430
- "headers": {
431
- "Accept": "application/json"
432
- },
433
- "query": "tag=prod"
434
- },
435
- "response": {
436
- "status": 200,
437
- "headers": {
438
- "Content-Type": "application/json"
439
- },
440
- "body": {
441
- "number": "1.2.3",
442
- "repository_ref": "package/pricing-service-1.2.3",
443
- "tags": [
444
- "prod"
445
- ]
446
- }
447
- }
448
- },
449
- {
450
- "description": "a request for the latest version",
451
- "provider_state": "no version exists for the Pricing Service",
452
- "request": {
453
- "method": "get",
454
- "path": "/pacticipants/Pricing%20Service/versions/latest",
455
- "headers": {
456
- "Accept": "application/json"
457
- }
458
- },
459
- "response": {
460
- "status": 404,
461
- "headers": {
462
- }
463
- }
464
- },
465
451
  {
466
452
  "description": "a request to tag the production version of Condor",
467
453
  "provider_state": "'Condor' exists in the pact-broker",
@@ -483,7 +469,11 @@
483
469
  "json_class": "Pact::Term",
484
470
  "data": {
485
471
  "generate": "http://localhost:1234/pacticipants/Condor/versions/1.3.0/tags/prod",
486
- "matcher": {"json_class":"Regexp","o":0,"s":"http://.*/pacticipants/Condor/versions/1.3.0/tags/prod"}
472
+ "matcher": {
473
+ "json_class": "Regexp",
474
+ "o": 0,
475
+ "s": "http://.*/pacticipants/Condor/versions/1.3.0/tags/prod"
476
+ }
487
477
  }
488
478
  }
489
479
  }
@@ -512,7 +502,11 @@
512
502
  "json_class": "Pact::Term",
513
503
  "data": {
514
504
  "generate": "http://localhost:1234/pacticipants/Condor/versions/1.3.0/tags/prod",
515
- "matcher": {"json_class":"Regexp","o":0,"s":"http://.*/pacticipants/Condor/versions/1.3.0/tags/prod"}
505
+ "matcher": {
506
+ "json_class": "Regexp",
507
+ "o": 0,
508
+ "s": "http://.*/pacticipants/Condor/versions/1.3.0/tags/prod"
509
+ }
516
510
  }
517
511
  }
518
512
  }
@@ -541,7 +535,11 @@
541
535
  "json_class": "Pact::Term",
542
536
  "data": {
543
537
  "generate": "http://localhost:1234/pacticipants/Condor/versions/1.3.0/tags/prod",
544
- "matcher": {"json_class":"Regexp","o":0,"s":"http://.*/pacticipants/Condor/versions/1.3.0/tags/prod"}
538
+ "matcher": {
539
+ "json_class": "Regexp",
540
+ "o": 0,
541
+ "s": "http://.*/pacticipants/Condor/versions/1.3.0/tags/prod"
542
+ }
545
543
  }
546
544
  }
547
545
  }
@@ -551,8 +549,6 @@
551
549
  }
552
550
  ],
553
551
  "metadata": {
554
- "pact_gem": {
555
- "version": "1.0.23"
556
- }
552
+ "pactSpecificationVersion": "1.0.0"
557
553
  }
558
554
  }