pact_broker-client 1.32.0 → 1.37.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/release_gem.yml +1 -0
  3. data/.github/workflows/test.yml +23 -0
  4. data/CHANGELOG.md +48 -0
  5. data/README.md +15 -3
  6. data/Rakefile +2 -0
  7. data/doc/pacts/markdown/Pact Broker Client - Pact Broker.md +331 -8
  8. data/lib/pact_broker/client.rb +1 -1
  9. data/lib/pact_broker/client/backports.rb +13 -0
  10. data/lib/pact_broker/client/cli/broker.rb +73 -28
  11. data/lib/pact_broker/client/cli/can_i_deploy_long_desc.txt +18 -9
  12. data/lib/pact_broker/client/cli/custom_thor.rb +9 -12
  13. data/lib/pact_broker/client/git.rb +43 -22
  14. data/lib/pact_broker/client/hal/entity.rb +27 -3
  15. data/lib/pact_broker/client/hal/http_client.rb +4 -0
  16. data/lib/pact_broker/client/hal/links.rb +39 -0
  17. data/lib/pact_broker/client/hal_client_methods.rb +11 -0
  18. data/lib/pact_broker/client/hash_refinements.rb +19 -0
  19. data/lib/pact_broker/client/matrix.rb +2 -1
  20. data/lib/pact_broker/client/matrix/text_formatter.rb +46 -11
  21. data/lib/pact_broker/client/publish_pacts.rb +93 -14
  22. data/lib/pact_broker/client/tasks/publication_task.rb +37 -6
  23. data/lib/pact_broker/client/version.rb +1 -1
  24. data/lib/pact_broker/client/versions/record_deployment.rb +109 -0
  25. data/pact-broker-client.gemspec +2 -0
  26. data/script/publish-pact.sh +7 -1
  27. data/script/trigger-release.sh +1 -1
  28. data/spec/lib/pact_broker/client/cli/broker_can_i_deploy_spec.rb +13 -2
  29. data/spec/lib/pact_broker/client/cli/broker_publish_spec.rb +108 -12
  30. data/spec/lib/pact_broker/client/git_spec.rb +39 -2
  31. data/spec/lib/pact_broker/client/hal/entity_spec.rb +4 -3
  32. data/spec/lib/pact_broker/client/matrix/text_formatter_spec.rb +29 -4
  33. data/spec/lib/pact_broker/client/publish_pacts_spec.rb +119 -7
  34. data/spec/lib/pact_broker/client/tasks/publication_task_spec.rb +88 -10
  35. data/spec/lib/pact_broker/client/versions/describe_spec.rb +0 -1
  36. data/spec/lib/pact_broker/client/versions/record_deployment_spec.rb +82 -0
  37. data/spec/pacts/pact_broker_client-pact_broker.json +335 -8
  38. data/spec/service_providers/pact_broker_client_create_version_spec.rb +89 -0
  39. data/spec/service_providers/pact_broker_client_matrix_spec.rb +4 -0
  40. data/spec/service_providers/pact_broker_client_versions_spec.rb +1 -2
  41. data/spec/service_providers/record_deployment_spec.rb +219 -0
  42. data/spec/support/matrix.json +6 -1
  43. data/spec/support/matrix.txt +3 -3
  44. data/spec/support/matrix_error.txt +3 -3
  45. data/spec/support/matrix_with_results.txt +10 -0
  46. data/tasks/pact.rake +2 -0
  47. metadata +44 -4
  48. data/.travis.yml +0 -11
@@ -279,6 +279,10 @@ module PactBroker::Client
279
279
  expect(matrix[:matrix].size).to eq 1
280
280
  end
281
281
  end
282
+
283
+ context "with an environment name" do
284
+ it "passes the environment name in the options"
285
+ end
282
286
  end
283
287
  end
284
288
  end
@@ -1,6 +1,5 @@
1
- require 'spec_helper'
2
- require 'pact_broker/client'
3
1
  require_relative 'pact_helper'
2
+ require 'pact_broker/client'
4
3
 
5
4
  describe PactBroker::Client::Versions, pact: true do
6
5
 
@@ -0,0 +1,219 @@
1
+ require 'service_providers/pact_helper'
2
+ require 'pact_broker/client/versions/record_deployment'
3
+
4
+ RSpec.describe "recording a deployment", pact: true do
5
+
6
+ include_context "pact broker"
7
+ include PactBrokerPactHelperMethods
8
+
9
+ let(:pacticipant_name) { "Foo" }
10
+ let(:version_number) { "5556b8149bf8bac76bc30f50a8a2dd4c22c85f30" }
11
+ let(:environment_name) { "test" }
12
+ let(:output) { "text" }
13
+ let(:replaced_previous_deployed_version) { true }
14
+ let(:params) do
15
+ {
16
+ pacticipant_name: pacticipant_name,
17
+ version_number: version_number,
18
+ environment_name: environment_name,
19
+ replaced_previous_deployed_version: replaced_previous_deployed_version,
20
+ output: output
21
+ }
22
+ end
23
+ let(:pact_broker_client_options) { {} }
24
+
25
+ subject { PactBroker::Client::Versions::RecordDeployment.call(params, broker_base_url, pact_broker_client_options) }
26
+
27
+ def mock_index
28
+ pact_broker
29
+ .given("the pb:pacticipant-version and pb:environments relations exist in the index resource")
30
+ .upon_receiving("a request for the index resource")
31
+ .with(
32
+ method: "GET",
33
+ path: '/',
34
+ headers: get_request_headers).
35
+ will_respond_with(
36
+ status: 200,
37
+ headers: pact_broker_response_headers,
38
+ body: {
39
+ _links: {
40
+ :'pb:pacticipant-version' => {
41
+ href: placeholder_url_term("pb:pacticipant-version", ["pacticipant", "version"])
42
+ },
43
+ :'pb:environments' => {
44
+ href: placeholder_url_term("pb:environments")
45
+ }
46
+ }
47
+ }
48
+ )
49
+ end
50
+
51
+ def mock_pacticipant_version_with_test_environment_available_for_deployment
52
+ pact_broker
53
+ .given("version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 of pacticipant Foo exists with a test environment available for deployment")
54
+ .upon_receiving("a request for a pacticipant version")
55
+ .with(
56
+ method: "GET",
57
+ path: "/HAL-REL-PLACEHOLDER-PB-PACTICIPANT-VERSION-Foo-5556b8149bf8bac76bc30f50a8a2dd4c22c85f30",
58
+ headers: get_request_headers
59
+ )
60
+ .will_respond_with(
61
+ status: 200,
62
+ headers: pact_broker_response_headers,
63
+ body: {
64
+ _links: {
65
+ "pb:record-deployment" => [
66
+ {
67
+ name: "test",
68
+ href: placeholder_url_term("pb:record-deployment-#{pacticipant_name}-#{version_number}-#{environment_name}")
69
+ }
70
+ ]
71
+ }
72
+ }
73
+ )
74
+ end
75
+
76
+ def mock_pacticipant_version_without_test_environment_available_for_deployment
77
+ pact_broker
78
+ .given("version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 of pacticipant Foo exists with 2 environments that aren't test available for deployment")
79
+ .upon_receiving("a request for a pacticipant version")
80
+ .with(
81
+ method: "GET",
82
+ path: "/HAL-REL-PLACEHOLDER-PB-PACTICIPANT-VERSION-Foo-5556b8149bf8bac76bc30f50a8a2dd4c22c85f30",
83
+ headers: get_request_headers
84
+ )
85
+ .will_respond_with(
86
+ status: 200,
87
+ headers: pact_broker_response_headers,
88
+ body: {
89
+ _links: {
90
+ "pb:record-deployment" => [
91
+ Pact.like(
92
+ name: "prod",
93
+ href: "href"
94
+ ),
95
+ Pact.like(
96
+ name: "dev",
97
+ href: "href"
98
+ ),
99
+ ]
100
+ }
101
+ }
102
+ )
103
+ end
104
+
105
+ def mock_pacticipant_version_not_found
106
+ pact_broker
107
+ .given("version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 of pacticipant Foo does not exist")
108
+ .upon_receiving("a request for a pacticipant version")
109
+ .with(
110
+ method: "GET",
111
+ path: "/HAL-REL-PLACEHOLDER-PB-PACTICIPANT-VERSION-Foo-5556b8149bf8bac76bc30f50a8a2dd4c22c85f30",
112
+ headers: get_request_headers
113
+ )
114
+ .will_respond_with(status: 404)
115
+ end
116
+
117
+ def mock_environments
118
+ pact_broker
119
+ .given("an environment with name test exists")
120
+ .upon_receiving("a request for the environments")
121
+ .with(
122
+ method: "GET",
123
+ path: "/HAL-REL-PLACEHOLDER-PB-ENVIRONMENTS",
124
+ headers: get_request_headers
125
+ )
126
+ .will_respond_with(
127
+ status: 200,
128
+ headers: pact_broker_response_headers,
129
+ body: {
130
+ _links: {
131
+ "pb:environments" => [
132
+ {
133
+ name: "test",
134
+ href: Pact.like("href")
135
+ }
136
+ ]
137
+ }
138
+ }
139
+ )
140
+ end
141
+
142
+ def mock_record_deployment
143
+ pact_broker
144
+ .given("version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 of pacticipant Foo exists with a test environment available for deployment")
145
+ .upon_receiving("a request to record a deployment")
146
+ .with(
147
+ method: "POST",
148
+ path: "/HAL-REL-PLACEHOLDER-PB-RECORD-DEPLOYMENT-FOO-5556B8149BF8BAC76BC30F50A8A2DD4C22C85F30-TEST",
149
+ headers: post_request_headers,
150
+ body: {
151
+ replacedPreviousDeployedVersion: replaced_previous_deployed_version
152
+ }
153
+ )
154
+ .will_respond_with(
155
+ status: 201,
156
+ headers: pact_broker_response_headers,
157
+ body: {
158
+ replacedPreviousDeployedVersion: replaced_previous_deployed_version
159
+ }
160
+ )
161
+ end
162
+
163
+ context "when the deployment is recorded successfully" do
164
+ before do
165
+ mock_index
166
+ mock_pacticipant_version_with_test_environment_available_for_deployment
167
+ mock_record_deployment
168
+ end
169
+
170
+ it "returns a success message" do
171
+ expect(subject.success).to be true
172
+ expect(subject.message).to eq "Recorded deployment of Foo version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 to test in the Pact Broker. Marked previous deployed version as undeployed."
173
+ end
174
+
175
+ context "when the output is json" do
176
+ let(:output) { "json" }
177
+
178
+ it "returns the JSON payload" do
179
+ expect(JSON.parse(subject.message)).to eq "replacedPreviousDeployedVersion" => replaced_previous_deployed_version
180
+ end
181
+ end
182
+ end
183
+
184
+ context "when the specified version does not exist" do
185
+ before do
186
+ mock_index
187
+ mock_pacticipant_version_not_found
188
+ end
189
+
190
+ it "returns an error response" do
191
+ expect(subject.success).to be false
192
+ expect(subject.message).to include "Foo version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 not found"
193
+ end
194
+ end
195
+
196
+ context "when the specified environment is not available for recording a deployment" do
197
+ before do
198
+ mock_index
199
+ mock_pacticipant_version_without_test_environment_available_for_deployment
200
+ mock_environments
201
+ end
202
+
203
+ context "when the specified environment does not exist" do
204
+ let(:environment_name) { "foo" }
205
+
206
+ it "returns an error response" do
207
+ expect(subject.success).to be false
208
+ expect(subject.message).to eq "No environment found with name 'foo'. Available options: test"
209
+ end
210
+ end
211
+
212
+ context "when the specified environment does exist" do
213
+ it "returns an error response" do
214
+ expect(subject.success).to be false
215
+ expect(subject.message).to eq "Environment 'test' is not an available option for recording a deployment of Foo. Available options: prod, dev"
216
+ end
217
+ end
218
+ end
219
+ end
@@ -20,7 +20,12 @@
20
20
  },
21
21
  "verificationResult": {
22
22
  "verifiedAt": "2017-10-10T12:49:04+11:00",
23
- "success": true
23
+ "success": true,
24
+ "_links": {
25
+ "self": {
26
+ "href": "http://result"
27
+ }
28
+ }
24
29
  },
25
30
  "pact": {
26
31
  "createdAt": "2017-10-10T12:49:04+11:00"
@@ -1,3 +1,3 @@
1
- CONSUMER | C.VERSION | PROVIDER | P.VERSION | SUCCESS?
2
- ---------|-----------|----------|-----------|---------
3
- Foo | 4 | Bar | 5 | true
1
+ CONSUMER | C.VERSION | PROVIDER | P.VERSION | SUCCESS? | RESULT#
2
+ ---------|-----------|----------|-----------|----------|--------
3
+ Foo | 4 | Bar | 5 | true | 1
@@ -1,3 +1,3 @@
1
- CONSUMER | C.VERSION | PROVIDER | P.VERSION | SUCCESS?
2
- ---------|-----------|----------|-----------|---------
3
- ??? | ??? | ??? | ??? | ???
1
+ CONSUMER | C.VERSION | PROVIDER | P.VERSION | SUCCESS? | RESULT#
2
+ ---------|-----------|----------|-----------|----------|--------
3
+ ??? | ??? | ??? | ??? | ??? |
@@ -0,0 +1,10 @@
1
+ CONSUMER | C.VERSION | PROVIDER | P.VERSION | SUCCESS? | RESULT#
2
+ ---------|-----------|----------|-----------|----------|--------
3
+ Foo | 4 | Bar | 5 | true | 1
4
+ Foo | 4 | Bar | 5 | ??? |
5
+ Foo | 4 | Bar | 5 | false | 2
6
+
7
+ VERIFICATION RESULTS
8
+ --------------------
9
+ 1. http://result (success)
10
+ 2. http://result (failure)
data/tasks/pact.rake CHANGED
@@ -5,6 +5,8 @@ PactBroker::Client::PublicationTask.new(:localhost) do | task |
5
5
  task.tag = `git rev-parse --abbrev-ref HEAD`.strip
6
6
  task.consumer_version = PactBroker::Client::VERSION
7
7
  task.pact_broker_base_url = "http://localhost:9292"
8
+ task.build_url = "http://ci"
9
+ # task.branch = "main"
8
10
  end
9
11
 
10
12
  PactBroker::Client::PublicationTask.new(:remote) do | task |
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pact_broker-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.32.0
4
+ version: 1.37.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Beth Skurrie
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-26 00:00:00.000000000 Z
11
+ date: 2021-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -86,6 +86,20 @@ dependencies:
86
86
  - - "~>"
87
87
  - !ruby/object:Gem::Version
88
88
  version: '13.0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: dig_rb
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '1.0'
96
+ type: :runtime
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '1.0'
89
103
  - !ruby/object:Gem::Dependency
90
104
  name: fakefs
91
105
  requirement: !ruby/object:Gem::Requirement
@@ -142,6 +156,20 @@ dependencies:
142
156
  - - "~>"
143
157
  - !ruby/object:Gem::Version
144
158
  version: '1.16'
159
+ - !ruby/object:Gem::Dependency
160
+ name: pact-support
161
+ requirement: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - '='
164
+ - !ruby/object:Gem::Version
165
+ version: 1.15.0
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - '='
171
+ - !ruby/object:Gem::Version
172
+ version: 1.15.0
145
173
  description: Client for the Pact Broker. Publish, retrieve and query pacts and verification
146
174
  results.
147
175
  email:
@@ -152,10 +180,10 @@ extensions: []
152
180
  extra_rdoc_files: []
153
181
  files:
154
182
  - ".github/workflows/release_gem.yml"
183
+ - ".github/workflows/test.yml"
155
184
  - ".github/workflows/trigger_pact_docs_update.yml"
156
185
  - ".gitignore"
157
186
  - ".rspec"
158
- - ".travis.yml"
159
187
  - CHANGELOG.md
160
188
  - Dockerfile
161
189
  - Gemfile
@@ -176,6 +204,7 @@ files:
176
204
  - example/scripts/publish-verification.sh
177
205
  - example/scripts/verification.json
178
206
  - lib/pact_broker/client.rb
207
+ - lib/pact_broker/client/backports.rb
179
208
  - lib/pact_broker/client/base_client.rb
180
209
  - lib/pact_broker/client/can_i_deploy.rb
181
210
  - lib/pact_broker/client/cli/broker.rb
@@ -194,7 +223,9 @@ files:
194
223
  - lib/pact_broker/client/hal/entry_point.rb
195
224
  - lib/pact_broker/client/hal/http_client.rb
196
225
  - lib/pact_broker/client/hal/link.rb
226
+ - lib/pact_broker/client/hal/links.rb
197
227
  - lib/pact_broker/client/hal_client_methods.rb
228
+ - lib/pact_broker/client/hash_refinements.rb
198
229
  - lib/pact_broker/client/matrix.rb
199
230
  - lib/pact_broker/client/matrix/formatter.rb
200
231
  - lib/pact_broker/client/matrix/json_formatter.rb
@@ -217,6 +248,7 @@ files:
217
248
  - lib/pact_broker/client/versions/describe.rb
218
249
  - lib/pact_broker/client/versions/formatter.rb
219
250
  - lib/pact_broker/client/versions/json_formatter.rb
251
+ - lib/pact_broker/client/versions/record_deployment.rb
220
252
  - lib/pact_broker/client/versions/text_formatter.rb
221
253
  - lib/pact_broker/client/webhooks/create.rb
222
254
  - lib/pact_broker/client/webhooks/test.rb
@@ -254,11 +286,13 @@ files:
254
286
  - spec/lib/pact_broker/client/retry_spec.rb
255
287
  - spec/lib/pact_broker/client/tasks/publication_task_spec.rb
256
288
  - spec/lib/pact_broker/client/versions/describe_spec.rb
289
+ - spec/lib/pact_broker/client/versions/record_deployment_spec.rb
257
290
  - spec/lib/pact_broker/client/versions_spec.rb
258
291
  - spec/lib/pact_broker/client/webhooks/create_spec.rb
259
292
  - spec/pacts/pact_broker_client-pact_broker.json
260
293
  - spec/service_providers/extra_goodies_spec.rb
261
294
  - spec/service_providers/list_latest_pact_versions_spec.rb.bak
295
+ - spec/service_providers/pact_broker_client_create_version_spec.rb
262
296
  - spec/service_providers/pact_broker_client_matrix_spec.rb
263
297
  - spec/service_providers/pact_broker_client_pacticipant_version_spec.rb
264
298
  - spec/service_providers/pact_broker_client_publish_spec.rb
@@ -269,6 +303,7 @@ files:
269
303
  - spec/service_providers/pact_broker_client_versions_spec.rb
270
304
  - spec/service_providers/pact_helper.rb
271
305
  - spec/service_providers/pacticipants_create_spec.rb
306
+ - spec/service_providers/record_deployment_spec.rb
272
307
  - spec/service_providers/webhooks_create_spec.rb
273
308
  - spec/spec_helper.rb
274
309
  - spec/support/cli_test_pacts/bar.json
@@ -277,6 +312,7 @@ files:
277
312
  - spec/support/matrix.json
278
313
  - spec/support/matrix.txt
279
314
  - spec/support/matrix_error.txt
315
+ - spec/support/matrix_with_results.txt
280
316
  - spec/support/pacticipant_get.json
281
317
  - spec/support/pacticipants_list.json
282
318
  - spec/support/pacts_latest_list.json
@@ -301,7 +337,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
301
337
  - !ruby/object:Gem::Version
302
338
  version: '0'
303
339
  requirements: []
304
- rubygems_version: 3.1.4
340
+ rubygems_version: 3.2.11
305
341
  signing_key:
306
342
  specification_version: 4
307
343
  summary: See description
@@ -333,11 +369,13 @@ test_files:
333
369
  - spec/lib/pact_broker/client/retry_spec.rb
334
370
  - spec/lib/pact_broker/client/tasks/publication_task_spec.rb
335
371
  - spec/lib/pact_broker/client/versions/describe_spec.rb
372
+ - spec/lib/pact_broker/client/versions/record_deployment_spec.rb
336
373
  - spec/lib/pact_broker/client/versions_spec.rb
337
374
  - spec/lib/pact_broker/client/webhooks/create_spec.rb
338
375
  - spec/pacts/pact_broker_client-pact_broker.json
339
376
  - spec/service_providers/extra_goodies_spec.rb
340
377
  - spec/service_providers/list_latest_pact_versions_spec.rb.bak
378
+ - spec/service_providers/pact_broker_client_create_version_spec.rb
341
379
  - spec/service_providers/pact_broker_client_matrix_spec.rb
342
380
  - spec/service_providers/pact_broker_client_pacticipant_version_spec.rb
343
381
  - spec/service_providers/pact_broker_client_publish_spec.rb
@@ -348,6 +386,7 @@ test_files:
348
386
  - spec/service_providers/pact_broker_client_versions_spec.rb
349
387
  - spec/service_providers/pact_helper.rb
350
388
  - spec/service_providers/pacticipants_create_spec.rb
389
+ - spec/service_providers/record_deployment_spec.rb
351
390
  - spec/service_providers/webhooks_create_spec.rb
352
391
  - spec/spec_helper.rb
353
392
  - spec/support/cli_test_pacts/bar.json
@@ -356,6 +395,7 @@ test_files:
356
395
  - spec/support/matrix.json
357
396
  - spec/support/matrix.txt
358
397
  - spec/support/matrix_error.txt
398
+ - spec/support/matrix_with_results.txt
359
399
  - spec/support/pacticipant_get.json
360
400
  - spec/support/pacticipants_list.json
361
401
  - spec/support/pacts_latest_list.json