pact_broker-client 1.33.0 → 1.37.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) 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 +47 -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 +76 -33
  11. data/lib/pact_broker/client/cli/can_i_deploy_long_desc.txt +18 -9
  12. data/lib/pact_broker/client/cli/create_or_update_webhook_long_desc.txt +3 -1
  13. data/lib/pact_broker/client/cli/create_webhook_long_desc.txt +2 -0
  14. data/lib/pact_broker/client/cli/custom_thor.rb +11 -17
  15. data/lib/pact_broker/client/git.rb +43 -22
  16. data/lib/pact_broker/client/hal/entity.rb +27 -3
  17. data/lib/pact_broker/client/hal/http_client.rb +4 -0
  18. data/lib/pact_broker/client/hal/links.rb +39 -0
  19. data/lib/pact_broker/client/hal_client_methods.rb +11 -0
  20. data/lib/pact_broker/client/hash_refinements.rb +19 -0
  21. data/lib/pact_broker/client/matrix.rb +2 -1
  22. data/lib/pact_broker/client/matrix/text_formatter.rb +46 -11
  23. data/lib/pact_broker/client/publish_pacts.rb +93 -14
  24. data/lib/pact_broker/client/tasks/publication_task.rb +37 -6
  25. data/lib/pact_broker/client/version.rb +1 -1
  26. data/lib/pact_broker/client/versions/record_deployment.rb +109 -0
  27. data/pact-broker-client.gemspec +1 -0
  28. data/script/publish-pact.sh +7 -1
  29. data/script/trigger-release.sh +1 -1
  30. data/spec/lib/pact_broker/client/cli/broker_can_i_deploy_spec.rb +15 -2
  31. data/spec/lib/pact_broker/client/cli/broker_publish_spec.rb +108 -12
  32. data/spec/lib/pact_broker/client/cli/custom_thor_spec.rb +1 -7
  33. data/spec/lib/pact_broker/client/git_spec.rb +39 -2
  34. data/spec/lib/pact_broker/client/hal/entity_spec.rb +4 -3
  35. data/spec/lib/pact_broker/client/matrix/text_formatter_spec.rb +29 -4
  36. data/spec/lib/pact_broker/client/publish_pacts_spec.rb +119 -7
  37. data/spec/lib/pact_broker/client/tasks/publication_task_spec.rb +88 -10
  38. data/spec/lib/pact_broker/client/versions/describe_spec.rb +0 -1
  39. data/spec/lib/pact_broker/client/versions/record_deployment_spec.rb +82 -0
  40. data/spec/pacts/pact_broker_client-pact_broker.json +335 -8
  41. data/spec/service_providers/pact_broker_client_create_version_spec.rb +89 -0
  42. data/spec/service_providers/pact_broker_client_matrix_spec.rb +4 -0
  43. data/spec/service_providers/pact_broker_client_versions_spec.rb +1 -2
  44. data/spec/service_providers/record_deployment_spec.rb +219 -0
  45. data/spec/support/matrix.json +6 -1
  46. data/spec/support/matrix.txt +3 -3
  47. data/spec/support/matrix_error.txt +3 -3
  48. data/spec/support/matrix_with_results.txt +10 -0
  49. data/tasks/pact.rake +2 -0
  50. metadata +30 -4
  51. 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.33.0
4
+ version: 1.37.1
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-11-10 00:00:00.000000000 Z
11
+ date: 2021-03-10 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
@@ -166,10 +180,10 @@ extensions: []
166
180
  extra_rdoc_files: []
167
181
  files:
168
182
  - ".github/workflows/release_gem.yml"
183
+ - ".github/workflows/test.yml"
169
184
  - ".github/workflows/trigger_pact_docs_update.yml"
170
185
  - ".gitignore"
171
186
  - ".rspec"
172
- - ".travis.yml"
173
187
  - CHANGELOG.md
174
188
  - Dockerfile
175
189
  - Gemfile
@@ -190,6 +204,7 @@ files:
190
204
  - example/scripts/publish-verification.sh
191
205
  - example/scripts/verification.json
192
206
  - lib/pact_broker/client.rb
207
+ - lib/pact_broker/client/backports.rb
193
208
  - lib/pact_broker/client/base_client.rb
194
209
  - lib/pact_broker/client/can_i_deploy.rb
195
210
  - lib/pact_broker/client/cli/broker.rb
@@ -208,7 +223,9 @@ files:
208
223
  - lib/pact_broker/client/hal/entry_point.rb
209
224
  - lib/pact_broker/client/hal/http_client.rb
210
225
  - lib/pact_broker/client/hal/link.rb
226
+ - lib/pact_broker/client/hal/links.rb
211
227
  - lib/pact_broker/client/hal_client_methods.rb
228
+ - lib/pact_broker/client/hash_refinements.rb
212
229
  - lib/pact_broker/client/matrix.rb
213
230
  - lib/pact_broker/client/matrix/formatter.rb
214
231
  - lib/pact_broker/client/matrix/json_formatter.rb
@@ -231,6 +248,7 @@ files:
231
248
  - lib/pact_broker/client/versions/describe.rb
232
249
  - lib/pact_broker/client/versions/formatter.rb
233
250
  - lib/pact_broker/client/versions/json_formatter.rb
251
+ - lib/pact_broker/client/versions/record_deployment.rb
234
252
  - lib/pact_broker/client/versions/text_formatter.rb
235
253
  - lib/pact_broker/client/webhooks/create.rb
236
254
  - lib/pact_broker/client/webhooks/test.rb
@@ -268,11 +286,13 @@ files:
268
286
  - spec/lib/pact_broker/client/retry_spec.rb
269
287
  - spec/lib/pact_broker/client/tasks/publication_task_spec.rb
270
288
  - spec/lib/pact_broker/client/versions/describe_spec.rb
289
+ - spec/lib/pact_broker/client/versions/record_deployment_spec.rb
271
290
  - spec/lib/pact_broker/client/versions_spec.rb
272
291
  - spec/lib/pact_broker/client/webhooks/create_spec.rb
273
292
  - spec/pacts/pact_broker_client-pact_broker.json
274
293
  - spec/service_providers/extra_goodies_spec.rb
275
294
  - spec/service_providers/list_latest_pact_versions_spec.rb.bak
295
+ - spec/service_providers/pact_broker_client_create_version_spec.rb
276
296
  - spec/service_providers/pact_broker_client_matrix_spec.rb
277
297
  - spec/service_providers/pact_broker_client_pacticipant_version_spec.rb
278
298
  - spec/service_providers/pact_broker_client_publish_spec.rb
@@ -283,6 +303,7 @@ files:
283
303
  - spec/service_providers/pact_broker_client_versions_spec.rb
284
304
  - spec/service_providers/pact_helper.rb
285
305
  - spec/service_providers/pacticipants_create_spec.rb
306
+ - spec/service_providers/record_deployment_spec.rb
286
307
  - spec/service_providers/webhooks_create_spec.rb
287
308
  - spec/spec_helper.rb
288
309
  - spec/support/cli_test_pacts/bar.json
@@ -291,6 +312,7 @@ files:
291
312
  - spec/support/matrix.json
292
313
  - spec/support/matrix.txt
293
314
  - spec/support/matrix_error.txt
315
+ - spec/support/matrix_with_results.txt
294
316
  - spec/support/pacticipant_get.json
295
317
  - spec/support/pacticipants_list.json
296
318
  - spec/support/pacts_latest_list.json
@@ -315,7 +337,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
315
337
  - !ruby/object:Gem::Version
316
338
  version: '0'
317
339
  requirements: []
318
- rubygems_version: 3.1.4
340
+ rubygems_version: 3.2.14
319
341
  signing_key:
320
342
  specification_version: 4
321
343
  summary: See description
@@ -347,11 +369,13 @@ test_files:
347
369
  - spec/lib/pact_broker/client/retry_spec.rb
348
370
  - spec/lib/pact_broker/client/tasks/publication_task_spec.rb
349
371
  - spec/lib/pact_broker/client/versions/describe_spec.rb
372
+ - spec/lib/pact_broker/client/versions/record_deployment_spec.rb
350
373
  - spec/lib/pact_broker/client/versions_spec.rb
351
374
  - spec/lib/pact_broker/client/webhooks/create_spec.rb
352
375
  - spec/pacts/pact_broker_client-pact_broker.json
353
376
  - spec/service_providers/extra_goodies_spec.rb
354
377
  - spec/service_providers/list_latest_pact_versions_spec.rb.bak
378
+ - spec/service_providers/pact_broker_client_create_version_spec.rb
355
379
  - spec/service_providers/pact_broker_client_matrix_spec.rb
356
380
  - spec/service_providers/pact_broker_client_pacticipant_version_spec.rb
357
381
  - spec/service_providers/pact_broker_client_publish_spec.rb
@@ -362,6 +386,7 @@ test_files:
362
386
  - spec/service_providers/pact_broker_client_versions_spec.rb
363
387
  - spec/service_providers/pact_helper.rb
364
388
  - spec/service_providers/pacticipants_create_spec.rb
389
+ - spec/service_providers/record_deployment_spec.rb
365
390
  - spec/service_providers/webhooks_create_spec.rb
366
391
  - spec/spec_helper.rb
367
392
  - spec/support/cli_test_pacts/bar.json
@@ -370,6 +395,7 @@ test_files:
370
395
  - spec/support/matrix.json
371
396
  - spec/support/matrix.txt
372
397
  - spec/support/matrix_error.txt
398
+ - spec/support/matrix_with_results.txt
373
399
  - spec/support/pacticipant_get.json
374
400
  - spec/support/pacticipants_list.json
375
401
  - spec/support/pacts_latest_list.json
data/.travis.yml DELETED
@@ -1,11 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.2.4
4
- - 2.4.1
5
-
6
- # before_install:
7
- # - (git show-ref | grep $(git log --pretty=%h -1) | sed 's|.*/\(.*\)|\1|' | sort -u | grep -v HEAD) || true
8
- # - (git show -s --pretty=%d HEAD) || true
9
- # - (git for-each-ref --format='%(objectname) %(refname:short)' refs/heads | awk "/^$(git rev-parse HEAD)/ {print \$2}") || true
10
- # - (git show -s --pretty=%D HEAD | tr -s ', ' '\n' | grep -v HEAD | head -n1) || true
11
- # - (git name-rev --name-only HEAD) || true