pact_broker-client 1.8.0 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +0 -17
  3. data/CHANGELOG.md +28 -0
  4. data/RELEASING.md +3 -14
  5. data/Rakefile +6 -1
  6. data/lib/pact_broker/client/base_client.rb +13 -1
  7. data/lib/pact_broker/client/can_i_deploy.rb +2 -3
  8. data/lib/pact_broker/client/cli/broker.rb +19 -8
  9. data/lib/pact_broker/client/cli/version_selector_options_parser.rb +5 -4
  10. data/lib/pact_broker/client/git.rb +15 -0
  11. data/lib/pact_broker/client/matrix.rb +17 -3
  12. data/lib/pact_broker/client/matrix/json_formatter.rb +2 -2
  13. data/lib/pact_broker/client/matrix/text_formatter.rb +3 -3
  14. data/lib/pact_broker/client/version.rb +1 -1
  15. data/pact-broker-client.gemspec +2 -3
  16. data/script/publish-pact.sh +1 -0
  17. data/script/release.sh +7 -0
  18. data/spec/integration/can_i_deploy_spec.rb +32 -0
  19. data/spec/lib/pact_broker/client/can_i_deploy_spec.rb +2 -2
  20. data/spec/lib/pact_broker/client/cli/broker_can_i_deploy_spec.rb +9 -1
  21. data/spec/lib/pact_broker/client/cli/broker_publish_spec.rb +25 -0
  22. data/spec/lib/pact_broker/client/cli/version_selector_options_parser_spec.rb +17 -14
  23. data/spec/lib/pact_broker/client/matrix/text_formatter_spec.rb +2 -2
  24. data/spec/lib/pact_broker/client/matrix_spec.rb +2 -1
  25. data/spec/pacts/pact_broker_client-pact_broker.json +272 -131
  26. data/spec/service_providers/pact_broker_client_matrix_spec.rb +89 -17
  27. data/spec/service_providers/pact_helper.rb +1 -0
  28. data/spec/support/matrix.json +26 -21
  29. data/spec/support/matrix.txt +1 -1
  30. metadata +11 -24
  31. data/Appraisals +0 -6
  32. data/gemfiles/default.gemfile +0 -7
  33. data/gemfiles/default.gemfile.lock +0 -106
  34. data/gemfiles/ruby_under_22.gemfile +0 -8
  35. data/gemfiles/ruby_under_22.gemfile.lock +0 -105
@@ -5,6 +5,7 @@ module PactBroker::Client::CLI
5
5
  describe ".broker" do
6
6
  before do
7
7
  allow(PactBroker::Client::PublishPacts).to receive(:call).and_return(true)
8
+ allow(PactBroker::Client::Git).to receive(:branch).and_return("bar")
8
9
  subject.options = OpenStruct.new(minimum_valid_options)
9
10
  end
10
11
 
@@ -79,6 +80,30 @@ module PactBroker::Client::CLI
79
80
  end
80
81
  end
81
82
 
83
+ context "with tag-with-git-branch" do
84
+ before do
85
+ subject.options = OpenStruct.new(
86
+ minimum_valid_options.merge(tag_with_git_branch: true)
87
+ )
88
+ end
89
+
90
+ it "determines the git branch name" do
91
+ expect(PactBroker::Client::Git).to receive(:branch)
92
+ invoke_broker
93
+ end
94
+
95
+ it "adds it to the list of tags when publishing" do
96
+ expect(PactBroker::Client::PublishPacts).to receive(:call).with(
97
+ anything,
98
+ anything,
99
+ anything,
100
+ ['bar'],
101
+ anything
102
+ )
103
+ invoke_broker
104
+ end
105
+ end
106
+
82
107
  context "with basic auth options specified" do
83
108
  before do
84
109
  subject.options = OpenStruct.new(
@@ -7,26 +7,29 @@ module PactBroker
7
7
 
8
8
  TEST_CASES = [
9
9
  [
10
- ["--name", "Foo", "--version", "1.2.3"],
11
- [{ name: "Foo", version: "1.2.3" } ]
10
+ ["--pacticipant", "Foo", "--version", "1.2.3"],
11
+ [{ pacticipant: "Foo", version: "1.2.3" } ]
12
12
  ],[
13
- ["-n", "Foo", "-a", "1.2.3"],
14
- [{ name: "Foo", version: "1.2.3" } ]
13
+ ["-a", "Foo", "-e", "1.2.3"],
14
+ [{ pacticipant: "Foo", version: "1.2.3" } ]
15
15
  ],[
16
- ["--name", "Foo"],
17
- [{ name: "Foo" } ]
16
+ ["--pacticipant", "Foo"],
17
+ [{ pacticipant: "Foo" } ]
18
18
  ],[
19
- ["--name", "Foo", "Bar"],
20
- [{ name: "Bar" } ]
19
+ ["--pacticipant", "Foo", "Bar"],
20
+ [{ pacticipant: "Bar" } ]
21
21
  ],[
22
- ["--name", "Foo", "--name", "Bar", "--version", "1.2.3"],
23
- [{ name: "Foo" }, { name: "Bar", version: "1.2.3" } ]
22
+ ["--pacticipant", "Foo", "--pacticipant", "Bar", "--version", "1.2.3"],
23
+ [{ pacticipant: "Foo" }, { pacticipant: "Bar", version: "1.2.3" } ]
24
24
  ],[
25
- ["--name", "Foo", "--wrong", "Bar", "--version", "1.2.3"],
26
- [{ name: "Foo", version: "1.2.3" } ]
25
+ ["--pacticipant", "Foo", "--wrong", "Bar", "--version", "1.2.3"],
26
+ [{ pacticipant: "Foo", version: "1.2.3" } ]
27
27
  ],[
28
- ["--name", "the-thing", "--version", "1.2.3"],
29
- [{ name: "the-thing", version: "1.2.3" } ]
28
+ ["--pacticipant", "the-thing", "--version", "1.2.3"],
29
+ [{ pacticipant: "the-thing", version: "1.2.3" } ]
30
+ ],[
31
+ ["--version", "1.2.3"],
32
+ [{ pacticipant: nil, version: "1.2.3" } ]
30
33
  ]
31
34
  ]
32
35
 
@@ -3,12 +3,12 @@ require 'pact_broker/client/matrix/text_formatter'
3
3
  module PactBroker
4
4
  module Client
5
5
  describe Matrix::TextFormatter do
6
- let(:matrix_lines) { JSON.parse(File.read('spec/support/matrix.json'), symbolize_names: true) }
6
+ let(:matrix_lines) { JSON.parse(File.read('spec/support/matrix.json'), symbolize_names: true)[:matrix] }
7
7
  let(:expected_matrix_lines) { File.read('spec/support/matrix.txt') }
8
8
 
9
9
  # SublimeText removes whitespace from the end of files when you save them,
10
10
  # so removing trailing whitespace before comparing
11
- subject { Matrix::TextFormatter.call(matrix_lines).split("\n").collect(&:strip).join("\n") }
11
+ subject { Matrix::TextFormatter.call(matrix: matrix_lines).split("\n").collect(&:strip).join("\n") }
12
12
 
13
13
  context "with valid data" do
14
14
  it "it has the right text" do
@@ -3,8 +3,9 @@ require 'pact_broker/client/matrix'
3
3
  module PactBroker
4
4
  module Client
5
5
  describe Matrix do
6
+ let(:matrix) { Matrix.new(base_url: 'http://example.org') }
7
+
6
8
  context "when the matrix resource is not found because the broker is the wrong version" do
7
- let(:matrix) { Matrix.new(base_url: 'http://example.org') }
8
9
  let!(:request) { stub_request(:get, /matrix/).to_return(status: 404) }
9
10
 
10
11
  it "raises a helpful error" do
@@ -18,17 +18,7 @@
18
18
  "response": {
19
19
  "status": 200,
20
20
  "headers": {
21
- "Content-Type": {
22
- "json_class": "Pact::Term",
23
- "data": {
24
- "generate": "application/hal+json",
25
- "matcher": {
26
- "json_class": "Regexp",
27
- "o": 0,
28
- "s": "application/hal\\+json"
29
- }
30
- }
31
- }
21
+ "Content-Type": "application/hal+json"
32
22
  },
33
23
  "body": {
34
24
  "_links": {
@@ -73,6 +63,12 @@
73
63
  }
74
64
  }
75
65
  ]
66
+ },
67
+ "matchingRules": {
68
+ "$.headers.Content-Type": {
69
+ "match": "regex",
70
+ "regex": "application\\/hal\\+json"
71
+ }
76
72
  }
77
73
  }
78
74
  },
@@ -88,17 +84,7 @@
88
84
  "response": {
89
85
  "status": 200,
90
86
  "headers": {
91
- "Content-Type": {
92
- "json_class": "Pact::Term",
93
- "data": {
94
- "generate": "application/hal+json",
95
- "matcher": {
96
- "json_class": "Regexp",
97
- "o": 0,
98
- "s": "application/hal\\+json"
99
- }
100
- }
101
- }
87
+ "Content-Type": "application/hal+json"
102
88
  },
103
89
  "body": {
104
90
  "_links": {
@@ -132,6 +118,12 @@
132
118
  }
133
119
  }
134
120
  ]
121
+ },
122
+ "matchingRules": {
123
+ "$.headers.Content-Type": {
124
+ "match": "regex",
125
+ "regex": "application\\/hal\\+json"
126
+ }
135
127
  }
136
128
  }
137
129
  },
@@ -147,17 +139,7 @@
147
139
  "response": {
148
140
  "status": 200,
149
141
  "headers": {
150
- "Content-Type": {
151
- "json_class": "Pact::Term",
152
- "data": {
153
- "generate": "application/hal+json",
154
- "matcher": {
155
- "json_class": "Regexp",
156
- "o": 0,
157
- "s": "application/hal\\+json"
158
- }
159
- }
160
- }
142
+ "Content-Type": "application/hal+json"
161
143
  },
162
144
  "body": {
163
145
  "_links": {
@@ -180,6 +162,12 @@
180
162
  "number": "1.3.0"
181
163
  }
182
164
  }
165
+ },
166
+ "matchingRules": {
167
+ "$.headers.Content-Type": {
168
+ "match": "regex",
169
+ "regex": "application\\/hal\\+json"
170
+ }
183
171
  }
184
172
  }
185
173
  },
@@ -204,38 +192,90 @@
204
192
  "request": {
205
193
  "method": "get",
206
194
  "path": "/matrix",
207
- "query": "selectors[]=Foo%2Fversion%2F1.2.3&selectors[]=Bar%2Fversion%2F4.5.6"
195
+ "query": "q[][pacticipant]=Foo&q[][version]=1.2.3&q[][pacticipant]=Bar&q[][version]=4.5.6"
208
196
  },
209
197
  "response": {
210
198
  "status": 200,
211
199
  "headers": {
212
200
  },
213
201
  "body": {
214
- "matrix": {
215
- "json_class": "Pact::SomethingLike",
216
- "contents": [
217
- {
218
- "consumer": {
219
- "name": "Foo",
220
- "version": {
221
- "number": "4"
222
- }
223
- },
224
- "provider": {
225
- "name": "Bar",
226
- "version": {
227
- "number": "5"
228
- }
229
- },
230
- "verificationResult": {
231
- "verifiedAt": "2017-10-10T12:49:04+11:00",
232
- "success": true
233
- },
234
- "pact": {
235
- "createdAt": "2017-10-10T12:49:04+11:00"
202
+ "summary": {
203
+ "compatible": true
204
+ },
205
+ "matrix": [
206
+ {
207
+ "consumer": {
208
+ "name": "Foo",
209
+ "version": {
210
+ "number": "4"
211
+ }
212
+ },
213
+ "provider": {
214
+ "name": "Bar",
215
+ "version": {
216
+ "number": "5"
236
217
  }
218
+ },
219
+ "verificationResult": {
220
+ "verifiedAt": "2017-10-10T12:49:04+11:00",
221
+ "success": true
222
+ },
223
+ "pact": {
224
+ "createdAt": "2017-10-10T12:49:04+11:00"
237
225
  }
238
- ]
226
+ }
227
+ ]
228
+ },
229
+ "matchingRules": {
230
+ "$.body": {
231
+ "match": "type"
232
+ }
233
+ }
234
+ }
235
+ },
236
+ {
237
+ "description": "a request for the compatibility matrix for Foo version 1.2.3 and Bar version 4.5.6",
238
+ "providerState": "the pact for Foo Thing version 1.2.3 has been verified by Bar version 4.5.6",
239
+ "request": {
240
+ "method": "get",
241
+ "path": "/matrix",
242
+ "query": "q[][pacticipant]=Foo%20Thing&q[][version]=1.2.3&q[][pacticipant]=Bar&q[][version]=4.5.6"
243
+ },
244
+ "response": {
245
+ "status": 200,
246
+ "headers": {
247
+ },
248
+ "body": {
249
+ "summary": {
250
+ "compatible": true
251
+ },
252
+ "matrix": [
253
+ {
254
+ "consumer": {
255
+ "name": "Foo",
256
+ "version": {
257
+ "number": "4"
258
+ }
259
+ },
260
+ "provider": {
261
+ "name": "Bar",
262
+ "version": {
263
+ "number": "5"
264
+ }
265
+ },
266
+ "verificationResult": {
267
+ "verifiedAt": "2017-10-10T12:49:04+11:00",
268
+ "success": true
269
+ },
270
+ "pact": {
271
+ "createdAt": "2017-10-10T12:49:04+11:00"
272
+ }
273
+ }
274
+ ]
275
+ },
276
+ "matchingRules": {
277
+ "$.body": {
278
+ "match": "type"
239
279
  }
240
280
  }
241
281
  }
@@ -246,17 +286,23 @@
246
286
  "request": {
247
287
  "method": "get",
248
288
  "path": "/matrix",
249
- "query": "selectors[]=Foo%2Fversion%2F1.2.3&selectors[]=Bar%2Fversion%2F9.9.9"
289
+ "query": "q[][pacticipant]=Foo&q[][version]=1.2.3&q[][pacticipant]=Bar&q[][version]=9.9.9"
250
290
  },
251
291
  "response": {
252
292
  "status": 400,
253
293
  "headers": {
254
294
  },
255
295
  "body": {
256
- "errors": {
257
- "json_class": "Pact::ArrayLike",
258
- "contents": "an error message",
296
+ "errors": [
297
+ "an error message"
298
+ ]
299
+ },
300
+ "matchingRules": {
301
+ "$.body.errors": {
259
302
  "min": 1
303
+ },
304
+ "$.body.errors[*].*": {
305
+ "match": "type"
260
306
  }
261
307
  }
262
308
  }
@@ -266,17 +312,138 @@
266
312
  "request": {
267
313
  "method": "get",
268
314
  "path": "/matrix",
269
- "query": "selectors[]=Foo%2Fversion%2F1.2.3&selectors[]=Bar%2Fversion%2F9.9.9"
315
+ "query": "q[][pacticipant]=Wiffle&q[][version]=1.2.3&q[][pacticipant]=Meep&q[][version]=9.9.9"
270
316
  },
271
317
  "response": {
272
318
  "status": 400,
273
319
  "headers": {
274
320
  },
275
321
  "body": {
276
- "errors": {
277
- "json_class": "Pact::ArrayLike",
278
- "contents": "an error message",
322
+ "errors": [
323
+ "an error message"
324
+ ]
325
+ },
326
+ "matchingRules": {
327
+ "$.body.errors": {
279
328
  "min": 1
329
+ },
330
+ "$.body.errors[*].*": {
331
+ "match": "type"
332
+ }
333
+ }
334
+ }
335
+ },
336
+ {
337
+ "description": "a request for the compatibility matrix for all versions of Foo and Bar",
338
+ "providerState": "the pact for Foo version 1.2.3 and 1.2.4 has been verified by Bar version 4.5.6",
339
+ "request": {
340
+ "method": "get",
341
+ "path": "/matrix",
342
+ "query": "q[][pacticipant]=Foo&q[][pacticipant]=Bar"
343
+ },
344
+ "response": {
345
+ "status": 200,
346
+ "headers": {
347
+ },
348
+ "body": {
349
+ "matrix": [
350
+ {
351
+ "consumer": {
352
+ "name": "Foo",
353
+ "version": {
354
+ "number": "4"
355
+ }
356
+ },
357
+ "provider": {
358
+ "name": "Bar",
359
+ "version": {
360
+ "number": "5"
361
+ }
362
+ },
363
+ "verificationResult": {
364
+ "verifiedAt": "2017-10-10T12:49:04+11:00",
365
+ "success": true
366
+ },
367
+ "pact": {
368
+ "createdAt": "2017-10-10T12:49:04+11:00"
369
+ }
370
+ },
371
+ {
372
+ "consumer": {
373
+ "name": "Foo",
374
+ "version": {
375
+ "number": "4"
376
+ }
377
+ },
378
+ "provider": {
379
+ "name": "Bar",
380
+ "version": {
381
+ "number": "5"
382
+ }
383
+ },
384
+ "verificationResult": {
385
+ "verifiedAt": "2017-10-10T12:49:04+11:00",
386
+ "success": true
387
+ },
388
+ "pact": {
389
+ "createdAt": "2017-10-10T12:49:04+11:00"
390
+ }
391
+ }
392
+ ]
393
+ },
394
+ "matchingRules": {
395
+ "$.body.matrix": {
396
+ "min": 2
397
+ },
398
+ "$.body.matrix[*].*": {
399
+ "match": "type"
400
+ }
401
+ }
402
+ }
403
+ },
404
+ {
405
+ "description": "a request for the successful rows of the compatibility matrix for all versions of Foo and Bar",
406
+ "providerState": "the pact for Foo version 1.2.3 has been successfully verified by Bar version 4.5.6, and 1.2.4 unsuccessfully by 9.9.9",
407
+ "request": {
408
+ "method": "get",
409
+ "path": "/matrix",
410
+ "query": "q[][pacticipant]=Foo&q[][pacticipant]=Bar&success[]=true"
411
+ },
412
+ "response": {
413
+ "status": 200,
414
+ "headers": {
415
+ },
416
+ "body": {
417
+ "summary": {
418
+ "compatible": true
419
+ },
420
+ "matrix": [
421
+ {
422
+ "consumer": {
423
+ "name": "Foo",
424
+ "version": {
425
+ "number": "4"
426
+ }
427
+ },
428
+ "provider": {
429
+ "name": "Bar",
430
+ "version": {
431
+ "number": "5"
432
+ }
433
+ },
434
+ "verificationResult": {
435
+ "verifiedAt": "2017-10-10T12:49:04+11:00",
436
+ "success": true
437
+ },
438
+ "pact": {
439
+ "createdAt": "2017-10-10T12:49:04+11:00"
440
+ }
441
+ }
442
+ ]
443
+ },
444
+ "matchingRules": {
445
+ "$.body": {
446
+ "match": "type"
280
447
  }
281
448
  }
282
449
  }
@@ -441,29 +608,19 @@
441
608
  "response": {
442
609
  "status": 500,
443
610
  "headers": {
444
- "Content-Type": {
445
- "json_class": "Pact::Term",
446
- "data": {
447
- "generate": "application/hal+json",
448
- "matcher": {
449
- "json_class": "Regexp",
450
- "o": 0,
451
- "s": "application/.*json"
452
- }
453
- }
454
- }
611
+ "Content-Type": "application/hal+json"
455
612
  },
456
613
  "body": {
457
- "message": {
458
- "json_class": "Pact::Term",
459
- "data": {
460
- "generate": "An error occurred",
461
- "matcher": {
462
- "json_class": "Regexp",
463
- "o": 0,
464
- "s": ".*"
465
- }
466
- }
614
+ "message": "An error occurred"
615
+ },
616
+ "matchingRules": {
617
+ "$.headers.Content-Type": {
618
+ "match": "regex",
619
+ "regex": "application\\/.*json"
620
+ },
621
+ "$.body.message": {
622
+ "match": "regex",
623
+ "regex": ".*"
467
624
  }
468
625
  }
469
626
  }
@@ -604,17 +761,7 @@
604
761
  "response": {
605
762
  "status": 200,
606
763
  "headers": {
607
- "Content-Type": {
608
- "json_class": "Pact::Term",
609
- "data": {
610
- "generate": "application/hal+json",
611
- "matcher": {
612
- "json_class": "Regexp",
613
- "o": 0,
614
- "s": "application/.*json"
615
- }
616
- }
617
- },
764
+ "Content-Type": "application/hal+json",
618
765
  "X-Pact-Consumer-Version": "1.3.0"
619
766
  },
620
767
  "body": {
@@ -627,6 +774,12 @@
627
774
  "interactions": [
628
775
 
629
776
  ]
777
+ },
778
+ "matchingRules": {
779
+ "$.headers.Content-Type": {
780
+ "match": "regex",
781
+ "regex": "application\\/.*json"
782
+ }
630
783
  }
631
784
  }
632
785
  },
@@ -689,19 +842,15 @@
689
842
  "body": {
690
843
  "_links": {
691
844
  "self": {
692
- "href": {
693
- "json_class": "Pact::Term",
694
- "data": {
695
- "generate": "http://localhost:1234/pacticipants/Condor/versions/1.3.0/tags/prod",
696
- "matcher": {
697
- "json_class": "Regexp",
698
- "o": 0,
699
- "s": "http://.*/pacticipants/Condor/versions/1.3.0/tags/prod"
700
- }
701
- }
702
- }
845
+ "href": "http://localhost:1234/pacticipants/Condor/versions/1.3.0/tags/prod"
703
846
  }
704
847
  }
848
+ },
849
+ "matchingRules": {
850
+ "$.body._links.self.href": {
851
+ "match": "regex",
852
+ "regex": "http:\\/\\/.*\\/pacticipants\\/Condor\\/versions\\/1.3.0\\/tags\\/prod"
853
+ }
705
854
  }
706
855
  }
707
856
  },
@@ -722,19 +871,15 @@
722
871
  "body": {
723
872
  "_links": {
724
873
  "self": {
725
- "href": {
726
- "json_class": "Pact::Term",
727
- "data": {
728
- "generate": "http://localhost:1234/pacticipants/Condor/versions/1.3.0/tags/prod",
729
- "matcher": {
730
- "json_class": "Regexp",
731
- "o": 0,
732
- "s": "http://.*/pacticipants/Condor/versions/1.3.0/tags/prod"
733
- }
734
- }
735
- }
874
+ "href": "http://localhost:1234/pacticipants/Condor/versions/1.3.0/tags/prod"
736
875
  }
737
876
  }
877
+ },
878
+ "matchingRules": {
879
+ "$.body._links.self.href": {
880
+ "match": "regex",
881
+ "regex": "http:\\/\\/.*\\/pacticipants\\/Condor\\/versions\\/1.3.0\\/tags\\/prod"
882
+ }
738
883
  }
739
884
  }
740
885
  },
@@ -755,26 +900,22 @@
755
900
  "body": {
756
901
  "_links": {
757
902
  "self": {
758
- "href": {
759
- "json_class": "Pact::Term",
760
- "data": {
761
- "generate": "http://localhost:1234/pacticipants/Condor/versions/1.3.0/tags/prod",
762
- "matcher": {
763
- "json_class": "Regexp",
764
- "o": 0,
765
- "s": "http://.*/pacticipants/Condor/versions/1.3.0/tags/prod"
766
- }
767
- }
768
- }
903
+ "href": "http://localhost:1234/pacticipants/Condor/versions/1.3.0/tags/prod"
769
904
  }
770
905
  }
906
+ },
907
+ "matchingRules": {
908
+ "$.body._links.self.href": {
909
+ "match": "regex",
910
+ "regex": "http:\\/\\/.*\\/pacticipants\\/Condor\\/versions\\/1.3.0\\/tags\\/prod"
911
+ }
771
912
  }
772
913
  }
773
914
  }
774
915
  ],
775
916
  "metadata": {
776
917
  "pactSpecification": {
777
- "version": "1.0.0"
918
+ "version": "2.0.0"
778
919
  }
779
920
  }
780
921
  }