pact_broker-client 1.35.0 → 1.38.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/release_gem.yml +1 -0
  3. data/CHANGELOG.md +34 -0
  4. data/Rakefile +2 -0
  5. data/doc/pacts/markdown/Pact Broker Client - Pact Broker.md +283 -0
  6. data/lib/pact_broker/client.rb +1 -1
  7. data/lib/pact_broker/client/backports.rb +13 -0
  8. data/lib/pact_broker/client/cli/broker.rb +112 -34
  9. data/lib/pact_broker/client/cli/can_i_deploy_long_desc.txt +18 -9
  10. data/lib/pact_broker/client/cli/create_or_update_webhook_long_desc.txt +3 -1
  11. data/lib/pact_broker/client/cli/create_webhook_long_desc.txt +2 -0
  12. data/lib/pact_broker/client/cli/custom_thor.rb +11 -17
  13. data/lib/pact_broker/client/git.rb +43 -22
  14. data/lib/pact_broker/client/hal/entity.rb +44 -3
  15. data/lib/pact_broker/client/hal/http_client.rb +5 -1
  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 +2 -0
  21. data/lib/pact_broker/client/publish_pacts.rb +85 -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/lib/pact_broker/client/versions/record_undeployment.rb +125 -0
  26. data/pact-broker-client.gemspec +1 -1
  27. data/script/publish-pact.sh +7 -1
  28. data/script/record-deployment.sh +4 -0
  29. data/script/trigger-release.sh +1 -1
  30. data/spec/lib/pact_broker/client/cli/broker_can_i_deploy_spec.rb +51 -6
  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/publish_pacts_spec.rb +99 -6
  36. data/spec/lib/pact_broker/client/tasks/publication_task_spec.rb +88 -10
  37. data/spec/lib/pact_broker/client/versions/describe_spec.rb +0 -1
  38. data/spec/lib/pact_broker/client/versions/record_deployment_spec.rb +82 -0
  39. data/spec/pacts/pact_broker_client-pact_broker.json +287 -0
  40. data/spec/service_providers/pact_broker_client_create_version_spec.rb +89 -0
  41. data/spec/service_providers/pact_broker_client_matrix_spec.rb +4 -0
  42. data/spec/service_providers/pact_broker_client_versions_spec.rb +1 -2
  43. data/spec/service_providers/record_deployment_spec.rb +219 -0
  44. data/spec/spec_helper.rb +2 -0
  45. data/tasks/pact.rake +2 -0
  46. metadata +19 -7
@@ -0,0 +1,89 @@
1
+ require_relative 'pact_helper'
2
+ require 'pact_broker/client'
3
+ require 'pact_broker/client/publish_pacts'
4
+
5
+ describe PactBroker::Client::Versions, pact: true do
6
+
7
+ include_context "pact broker"
8
+
9
+
10
+ describe "creating a pacticipant version" do
11
+ before do
12
+ allow(publish_pacts).to receive(:consumer_names).and_return(["Foo"])
13
+ allow($stdout).to receive(:puts)
14
+ end
15
+ let(:version_path) { "/HAL-REL-PLACEHOLDER-INDEX-PB-PACTICIPANT-VERSION-{pacticipant}-{version}" }
16
+ let(:version_url) { pact_broker.mock_service_base_url + version_path }
17
+ let(:number) { "26f353580936ad3b9baddb17b00e84f33c69e7cb" }
18
+ let(:branch) { "main" }
19
+ let(:build_url) { "http://my-ci/builds/1" }
20
+ let(:consumer_version_params) { { number: number, branch: branch, build_url: build_url } }
21
+ let(:publish_pacts) { PactBroker::Client::PublishPacts.new(pact_broker.mock_service_base_url, ["some-pact.json"], consumer_version_params, {}) }
22
+ let(:provider_state) { "version #{number} of pacticipant Foo does not exist" }
23
+ let(:expected_response_status) { 201 }
24
+
25
+ subject { publish_pacts.send(:create_consumer_versions) }
26
+
27
+ before do
28
+ pact_broker
29
+ .given("the pb:pacticipant-version relation exists 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: Pact.term(version_url, /http:\/\/.*{pacticipant}.*{version}/)
42
+ }
43
+ }
44
+ }
45
+ )
46
+
47
+ pact_broker
48
+ .given(provider_state)
49
+ .upon_receiving("a request to create a pacticipant version")
50
+ .with(
51
+ method: :put,
52
+ path: "/HAL-REL-PLACEHOLDER-INDEX-PB-PACTICIPANT-VERSION-Foo-#{number}",
53
+ headers: put_request_headers,
54
+ body: {
55
+ branch: branch,
56
+ buildUrl: build_url
57
+ }).
58
+ will_respond_with(
59
+ status: expected_response_status,
60
+ headers: pact_broker_response_headers,
61
+ body: {
62
+ number: number,
63
+ branch: branch,
64
+ buildUrl: build_url,
65
+ _links: {
66
+ self: {
67
+ href: Pact.term('http://localhost:1234/some-url', %r{http://.*})
68
+ }
69
+ }
70
+ }
71
+ )
72
+ end
73
+
74
+ context "when the version does not already exist" do
75
+ it "returns true" do
76
+ expect(subject).to be true
77
+ end
78
+ end
79
+
80
+ context "when the version does exist" do
81
+ let(:provider_state) { "version #{number} of pacticipant Foo does exist" }
82
+ let(:expected_response_status) { 200 }
83
+
84
+ it "returns true" do
85
+ expect(subject).to be true
86
+ end
87
+ end
88
+ end
89
+ end
@@ -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
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require 'webmock/rspec'
2
2
 
3
+ ENV['PACT_BROKER_FEATURES'] = 'deployments'
4
+
3
5
  WebMock.disable_net_connect!(allow_localhost: true)
4
6
 
5
7
  require "./spec/support/shared_context.rb"
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.35.0
4
+ version: 1.38.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: 2021-01-21 00:00:00.000000000 Z
11
+ date: 2021-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -160,16 +160,16 @@ dependencies:
160
160
  name: pact-support
161
161
  requirement: !ruby/object:Gem::Requirement
162
162
  requirements:
163
- - - '='
163
+ - - "~>"
164
164
  - !ruby/object:Gem::Version
165
- version: 1.15.0
165
+ version: '1.16'
166
166
  type: :development
167
167
  prerelease: false
168
168
  version_requirements: !ruby/object:Gem::Requirement
169
169
  requirements:
170
- - - '='
170
+ - - "~>"
171
171
  - !ruby/object:Gem::Version
172
- version: 1.15.0
172
+ version: '1.16'
173
173
  description: Client for the Pact Broker. Publish, retrieve and query pacts and verification
174
174
  results.
175
175
  email:
@@ -204,6 +204,7 @@ files:
204
204
  - example/scripts/publish-verification.sh
205
205
  - example/scripts/verification.json
206
206
  - lib/pact_broker/client.rb
207
+ - lib/pact_broker/client/backports.rb
207
208
  - lib/pact_broker/client/base_client.rb
208
209
  - lib/pact_broker/client/can_i_deploy.rb
209
210
  - lib/pact_broker/client/cli/broker.rb
@@ -222,7 +223,9 @@ files:
222
223
  - lib/pact_broker/client/hal/entry_point.rb
223
224
  - lib/pact_broker/client/hal/http_client.rb
224
225
  - lib/pact_broker/client/hal/link.rb
226
+ - lib/pact_broker/client/hal/links.rb
225
227
  - lib/pact_broker/client/hal_client_methods.rb
228
+ - lib/pact_broker/client/hash_refinements.rb
226
229
  - lib/pact_broker/client/matrix.rb
227
230
  - lib/pact_broker/client/matrix/formatter.rb
228
231
  - lib/pact_broker/client/matrix/json_formatter.rb
@@ -245,6 +248,8 @@ files:
245
248
  - lib/pact_broker/client/versions/describe.rb
246
249
  - lib/pact_broker/client/versions/formatter.rb
247
250
  - lib/pact_broker/client/versions/json_formatter.rb
251
+ - lib/pact_broker/client/versions/record_deployment.rb
252
+ - lib/pact_broker/client/versions/record_undeployment.rb
248
253
  - lib/pact_broker/client/versions/text_formatter.rb
249
254
  - lib/pact_broker/client/webhooks/create.rb
250
255
  - lib/pact_broker/client/webhooks/test.rb
@@ -253,6 +258,7 @@ files:
253
258
  - script/create-pacticipant.sh
254
259
  - script/generate-cli-usage.sh
255
260
  - script/publish-pact.sh
261
+ - script/record-deployment.sh
256
262
  - script/release.sh
257
263
  - script/trigger-release.sh
258
264
  - spec/integration/can_i_deploy_spec.rb
@@ -282,11 +288,13 @@ files:
282
288
  - spec/lib/pact_broker/client/retry_spec.rb
283
289
  - spec/lib/pact_broker/client/tasks/publication_task_spec.rb
284
290
  - spec/lib/pact_broker/client/versions/describe_spec.rb
291
+ - spec/lib/pact_broker/client/versions/record_deployment_spec.rb
285
292
  - spec/lib/pact_broker/client/versions_spec.rb
286
293
  - spec/lib/pact_broker/client/webhooks/create_spec.rb
287
294
  - spec/pacts/pact_broker_client-pact_broker.json
288
295
  - spec/service_providers/extra_goodies_spec.rb
289
296
  - spec/service_providers/list_latest_pact_versions_spec.rb.bak
297
+ - spec/service_providers/pact_broker_client_create_version_spec.rb
290
298
  - spec/service_providers/pact_broker_client_matrix_spec.rb
291
299
  - spec/service_providers/pact_broker_client_pacticipant_version_spec.rb
292
300
  - spec/service_providers/pact_broker_client_publish_spec.rb
@@ -297,6 +305,7 @@ files:
297
305
  - spec/service_providers/pact_broker_client_versions_spec.rb
298
306
  - spec/service_providers/pact_helper.rb
299
307
  - spec/service_providers/pacticipants_create_spec.rb
308
+ - spec/service_providers/record_deployment_spec.rb
300
309
  - spec/service_providers/webhooks_create_spec.rb
301
310
  - spec/spec_helper.rb
302
311
  - spec/support/cli_test_pacts/bar.json
@@ -330,7 +339,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
330
339
  - !ruby/object:Gem::Version
331
340
  version: '0'
332
341
  requirements: []
333
- rubygems_version: 3.2.6
342
+ rubygems_version: 3.2.15
334
343
  signing_key:
335
344
  specification_version: 4
336
345
  summary: See description
@@ -362,11 +371,13 @@ test_files:
362
371
  - spec/lib/pact_broker/client/retry_spec.rb
363
372
  - spec/lib/pact_broker/client/tasks/publication_task_spec.rb
364
373
  - spec/lib/pact_broker/client/versions/describe_spec.rb
374
+ - spec/lib/pact_broker/client/versions/record_deployment_spec.rb
365
375
  - spec/lib/pact_broker/client/versions_spec.rb
366
376
  - spec/lib/pact_broker/client/webhooks/create_spec.rb
367
377
  - spec/pacts/pact_broker_client-pact_broker.json
368
378
  - spec/service_providers/extra_goodies_spec.rb
369
379
  - spec/service_providers/list_latest_pact_versions_spec.rb.bak
380
+ - spec/service_providers/pact_broker_client_create_version_spec.rb
370
381
  - spec/service_providers/pact_broker_client_matrix_spec.rb
371
382
  - spec/service_providers/pact_broker_client_pacticipant_version_spec.rb
372
383
  - spec/service_providers/pact_broker_client_publish_spec.rb
@@ -377,6 +388,7 @@ test_files:
377
388
  - spec/service_providers/pact_broker_client_versions_spec.rb
378
389
  - spec/service_providers/pact_helper.rb
379
390
  - spec/service_providers/pacticipants_create_spec.rb
391
+ - spec/service_providers/record_deployment_spec.rb
380
392
  - spec/service_providers/webhooks_create_spec.rb
381
393
  - spec/spec_helper.rb
382
394
  - spec/support/cli_test_pacts/bar.json