pact_broker-client 1.41.0 → 1.42.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +17 -0
  3. data/lib/pact_broker/client/backports.rb +9 -0
  4. data/lib/pact_broker/client/base_command.rb +95 -0
  5. data/lib/pact_broker/client/cli/broker.rb +11 -19
  6. data/lib/pact_broker/client/cli/custom_thor.rb +12 -0
  7. data/lib/pact_broker/client/cli/environment_commands.rb +70 -0
  8. data/lib/pact_broker/client/cli/pacticipant_commands.rb +44 -0
  9. data/lib/pact_broker/client/environments.rb +3 -0
  10. data/lib/pact_broker/client/environments/create_environment.rb +31 -0
  11. data/lib/pact_broker/client/environments/delete_environment.rb +27 -0
  12. data/lib/pact_broker/client/environments/describe_environment.rb +36 -0
  13. data/lib/pact_broker/client/environments/environment_command.rb +66 -0
  14. data/lib/pact_broker/client/environments/list_environments.rb +30 -0
  15. data/lib/pact_broker/client/environments/text_formatter.rb +30 -0
  16. data/lib/pact_broker/client/environments/update_environment.rb +31 -0
  17. data/lib/pact_broker/client/generate_display_name.rb +27 -0
  18. data/lib/pact_broker/client/hal/entity.rb +10 -3
  19. data/lib/pact_broker/client/hal/http_client.rb +5 -0
  20. data/lib/pact_broker/client/hal/link.rb +8 -0
  21. data/lib/pact_broker/client/hal_client_methods.rb +1 -3
  22. data/lib/pact_broker/client/matrix/text_formatter.rb +21 -13
  23. data/lib/pact_broker/client/pacticipants.rb +6 -0
  24. data/lib/pact_broker/client/pacticipants/create.rb +24 -34
  25. data/lib/pact_broker/client/pacticipants/list.rb +34 -0
  26. data/lib/pact_broker/client/pacticipants/text_formatter.rb +41 -0
  27. data/lib/pact_broker/client/string_refinements.rb +56 -0
  28. data/lib/pact_broker/client/version.rb +1 -1
  29. data/pact-broker-client.gemspec +1 -0
  30. data/spec/fixtures/approvals/describe_environment.approved.txt +7 -0
  31. data/spec/fixtures/approvals/list_environments.approved.txt +3 -0
  32. data/spec/lib/pact_broker/client/cli/broker_can_i_deploy_spec.rb +3 -3
  33. data/spec/lib/pact_broker/client/cli/broker_publish_spec.rb +1 -1
  34. data/spec/lib/pact_broker/client/cli/broker_run_webhook_commands_spec.rb +3 -3
  35. data/spec/lib/pact_broker/client/environments/delete_environment_spec.rb +120 -0
  36. data/spec/lib/pact_broker/client/environments/describe_environment_spec.rb +89 -0
  37. data/spec/lib/pact_broker/client/environments/update_environment_spec.rb +167 -0
  38. data/spec/lib/pact_broker/client/generate_display_name_spec.rb +39 -0
  39. data/spec/lib/pact_broker/client/hal/entity_spec.rb +2 -2
  40. data/spec/lib/pact_broker/client/pacticipants/create_spec.rb +2 -2
  41. data/spec/service_providers/create_environment_spec.rb +78 -0
  42. data/spec/service_providers/list_environments_spec.rb +77 -0
  43. data/spec/service_providers/pacticipants_create_spec.rb +5 -4
  44. data/spec/spec_helper.rb +1 -0
  45. data/spec/support/approvals.rb +1 -1
  46. metadata +48 -3
@@ -0,0 +1,39 @@
1
+ require 'pact_broker/client/generate_display_name'
2
+
3
+ module PactBroker
4
+ module Client
5
+ describe GenerateDisplayName do
6
+ describe ".call" do
7
+ TEST_CASES = {
8
+ "foo" => "Foo",
9
+ "MyService" => "My Service",
10
+ "my-service" => "My Service",
11
+ "my_service" => "My Service",
12
+ "my service" => "My Service",
13
+ "ABCService" => "ABC Service",
14
+ "A4Service" => "A4 Service",
15
+ "SNSPactEventConsumer" => "SNS Pact Event Consumer",
16
+ "AWSSummiteerWeb" => "AWS Summiteer Web",
17
+ "Beer-Consumer" => "Beer Consumer",
18
+ "foo.pretend-consumer" => "Foo Pretend Consumer",
19
+ "Client-XX" => "Client XX",
20
+ "providerJSWorkshop" => "Provider JS Workshop",
21
+ "e2e Provider Example" => "E2e Provider Example",
22
+ "MP - Our Provider" => "MP - Our Provider",
23
+ "PoC - Pact-broker-consumer" => "PoC - Pact Broker Consumer",
24
+ "QB-DATABASE Service" => "QB DATABASE Service",
25
+ "Support Species App (Provider)" => "Support Species App (Provider)",
26
+ 9 => "9",
27
+ "" => "",
28
+ nil => nil
29
+ }
30
+
31
+ TEST_CASES.each do | name, expected_display_name |
32
+ it "converts #{name.inspect} to #{expected_display_name.inspect}" do
33
+ expect(GenerateDisplayName.call(name)).to eq expected_display_name
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -73,7 +73,7 @@ module PactBroker::Client
73
73
  subject(:entity) { ErrorEntity.new("http://pact", pact_hash, http_client) }
74
74
 
75
75
  it "raises an error" do
76
- expect { entity.assert_success! }.to raise_error ErrorResponseReturned, "Error retrieving http://pact status="
76
+ expect { entity.assert_success! }.to raise_error ErrorResponseReturned, "Error making request to http://pact status="
77
77
  end
78
78
  end
79
79
 
@@ -83,7 +83,7 @@ module PactBroker::Client
83
83
  subject(:entity) { ErrorEntity.new("http://pact", pact_hash, http_client, response) }
84
84
 
85
85
  it "raises an error" do
86
- expect { entity.assert_success! }.to raise_error ErrorResponseReturned, "Error retrieving http://pact status=200 body"
86
+ expect { entity.assert_success! }.to raise_error ErrorResponseReturned, "Error making request to http://pact status=200 body"
87
87
  end
88
88
  end
89
89
  end
@@ -8,11 +8,11 @@ module PactBroker
8
8
  before do
9
9
  allow_any_instance_of(PactBroker::Client::Hal::HttpClient).to receive(:sleep)
10
10
  end
11
- let(:pact_broker_client_options) { {} }
11
+ let(:pact_broker_client_options) { { pact_broker_base_url: broker_base_url} }
12
12
  let(:broker_base_url) { "http://url" }
13
13
  let(:params) { { name: 'Foo' } }
14
14
 
15
- subject { Create.call(params, broker_base_url, pact_broker_client_options)}
15
+ subject { Create.call(params, {}, pact_broker_client_options)}
16
16
 
17
17
  context "when there is an http error" do
18
18
  let!(:index_request) do
@@ -0,0 +1,78 @@
1
+ require 'service_providers/pact_helper'
2
+ require 'pact_broker/client/environments/create_environment'
3
+
4
+ RSpec.describe "create an environment", pact: true, skip: true do
5
+ include_context "pact broker"
6
+ include PactBrokerPactHelperMethods
7
+
8
+ let(:params) do
9
+ {
10
+ name: "test",
11
+ display_name: "Test",
12
+ production: false,
13
+ contact_name: "Foo team",
14
+ contact_email_address: "foo@bar.com"
15
+
16
+ }
17
+ end
18
+ let(:pact_broker_client_options) { {} }
19
+ let(:request_body) do
20
+ {
21
+ name: "test",
22
+ displayName: "Test",
23
+ production: false,
24
+ contacts: [{
25
+ name: "Foo team",
26
+ details: {
27
+ emailAddress: "foo@bar.com"
28
+ }
29
+ }]
30
+ }
31
+ end
32
+
33
+ subject { PactBroker::Client::Environments::CreateEnvironment.call(params, broker_base_url, pact_broker_client_options) }
34
+
35
+ def mock_index
36
+ pact_broker
37
+ .given("the pb:environments relation exists in the index resource")
38
+ .upon_receiving("a request for the index resource")
39
+ .with(
40
+ method: "GET",
41
+ path: '/',
42
+ headers: get_request_headers).
43
+ will_respond_with(
44
+ status: 200,
45
+ headers: pact_broker_response_headers,
46
+ body: {
47
+ _links: {
48
+ :'pb:environments' => {
49
+ href: placeholder_url_term("pb:environments")
50
+ }
51
+ }
52
+ }
53
+ )
54
+ end
55
+
56
+ def mock_environment_creation_request
57
+ pact_broker
58
+ .upon_receiving("a request to create an environment")
59
+ .with(
60
+ method: "POST",
61
+ path: "/HAL-REL-PLACEHOLDER-PB-ENVIRONMENTS",
62
+ headers: post_request_headers,
63
+ body: request_body
64
+ )
65
+ .will_respond_with(
66
+ status: 201,
67
+ headers: pact_broker_response_headers,
68
+ body: request_body.merge("uuid" => Pact.like("ffe683ef-dcd7-4e4f-877d-f6eb3db8e86e"))
69
+ )
70
+ end
71
+
72
+ it "returns a success result" do
73
+ mock_index
74
+ mock_environment_creation_request
75
+ expect(subject.success).to be true
76
+ expect(subject.message).to include "Created test environment in the Pact Broker with UUID ffe683ef-dcd7-4e4f-877d-f6eb3db8e86e"
77
+ end
78
+ end
@@ -0,0 +1,77 @@
1
+ require 'service_providers/pact_helper'
2
+ require 'pact_broker/client/environments/list_environments'
3
+
4
+ RSpec.describe "list environments", pact: true, skip: true do
5
+ include_context "pact broker"
6
+ include PactBrokerPactHelperMethods
7
+
8
+ let(:params) { { output: output } }
9
+ let(:output) { "text" }
10
+ let(:pact_broker_client_options) { {} }
11
+ let(:response_body) do
12
+ {
13
+ _embedded: {
14
+ environments: Pact.each_like(
15
+ {
16
+ uuid: "78e85fb2-9df1-48da-817e-c9bea6294e01",
17
+ name: "test",
18
+ displayName: "Test",
19
+ production: false,
20
+ contacts: [{
21
+ name: "Foo team",
22
+ details: {
23
+ emailAddress: "foo@bar.com"
24
+ }
25
+ }]
26
+ }
27
+ )
28
+ }
29
+ }
30
+ end
31
+
32
+ subject { PactBroker::Client::Environments::ListEnvironments.call(params, broker_base_url, pact_broker_client_options) }
33
+
34
+ def mock_index
35
+ pact_broker
36
+ .given("the pb:environments relation exists in the index resource")
37
+ .upon_receiving("a request for the index resource")
38
+ .with(
39
+ method: "GET",
40
+ path: '/',
41
+ headers: get_request_headers).
42
+ will_respond_with(
43
+ status: 200,
44
+ headers: pact_broker_response_headers,
45
+ body: {
46
+ _links: {
47
+ :'pb:environments' => {
48
+ href: placeholder_url_term("pb:environments")
49
+ }
50
+ }
51
+ }
52
+ )
53
+ end
54
+
55
+ def mock_get_environments
56
+ pact_broker
57
+ .given("an environment exists")
58
+ .upon_receiving("a request to list the environments")
59
+ .with(
60
+ method: "GET",
61
+ path: "/HAL-REL-PLACEHOLDER-PB-ENVIRONMENTS",
62
+ headers: get_request_headers
63
+ )
64
+ .will_respond_with(
65
+ status: 200,
66
+ headers: pact_broker_response_headers,
67
+ body: response_body
68
+ )
69
+ end
70
+
71
+ it "returns a success result" do
72
+ mock_index
73
+ mock_get_environments
74
+ expect(subject.success).to be true
75
+ Approvals.verify(subject.message, :name => "list_environments", format: :txt)
76
+ end
77
+ end
@@ -54,9 +54,10 @@ RSpec.describe "creating or updating a pacticipant", pact: true do
54
54
  }
55
55
  end
56
56
 
57
- let(:pact_broker_client_options) { {} }
57
+ let(:pact_broker_client_options) { { pact_broker_base_url: broker_base_url} }
58
+ let(:options) { {} }
58
59
 
59
- subject { PactBroker::Client::Pacticipants2::Create.call(params, broker_base_url, pact_broker_client_options) }
60
+ subject { PactBroker::Client::Pacticipants2::Create.call(params, options, pact_broker_client_options) }
60
61
 
61
62
  context "when the pacticipant does not already exist" do
62
63
  before do
@@ -81,7 +82,7 @@ RSpec.describe "creating or updating a pacticipant", pact: true do
81
82
  it "returns a CommandResult with success = true" do
82
83
  expect(subject).to be_a PactBroker::Client::CommandResult
83
84
  expect(subject.success).to be true
84
- expect(subject.message).to eq "Pacticipant \"Foo\" created"
85
+ expect(subject.message).to include "Pacticipant \"Foo\" created"
85
86
  end
86
87
  end
87
88
 
@@ -112,7 +113,7 @@ RSpec.describe "creating or updating a pacticipant", pact: true do
112
113
  it "returns a CommandResult with success = true" do
113
114
  expect(subject).to be_a PactBroker::Client::CommandResult
114
115
  expect(subject.success).to be true
115
- expect(subject.message).to eq "Pacticipant \"Foo\" updated"
116
+ expect(subject.message).to include "Pacticipant \"Foo\" updated"
116
117
  end
117
118
  end
118
119
  end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'webmock/rspec'
2
+ require 'rspec/its'
2
3
 
3
4
  ENV['PACT_BROKER_FEATURES'] = 'deployments publish_contracts ignore'
4
5
 
@@ -9,7 +9,7 @@ def print_diff(exception)
9
9
  parts = exception.message.split('"')
10
10
  received_file = parts[1]
11
11
  approved_file = parts[3]
12
- if File.exist?(received_file) && File.exist?(approved_file)
12
+ if File.exist?(received_file) && File.exist?(approved_file) && received_file.end_with?(".json") && approved_file.end_with?(".json")
13
13
  received_hash = JSON.parse(File.read(received_file))
14
14
  approved_hash = JSON.parse(File.read(approved_file))
15
15
  diff = Pact::Matchers.diff(approved_hash, received_hash)
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.41.0
4
+ version: 1.42.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: 2021-05-24 00:00:00.000000000 Z
11
+ date: 2021-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -190,6 +190,20 @@ dependencies:
190
190
  - - "<"
191
191
  - !ruby/object:Gem::Version
192
192
  version: 1.0.0
193
+ - !ruby/object:Gem::Dependency
194
+ name: rspec-its
195
+ requirement: !ruby/object:Gem::Requirement
196
+ requirements:
197
+ - - "~>"
198
+ - !ruby/object:Gem::Version
199
+ version: '1.3'
200
+ type: :development
201
+ prerelease: false
202
+ version_requirements: !ruby/object:Gem::Requirement
203
+ requirements:
204
+ - - "~>"
205
+ - !ruby/object:Gem::Version
206
+ version: '1.3'
193
207
  description: Client for the Pact Broker. Publish, retrieve and query pacts and verification
194
208
  results.
195
209
  email:
@@ -226,18 +240,30 @@ files:
226
240
  - lib/pact_broker/client.rb
227
241
  - lib/pact_broker/client/backports.rb
228
242
  - lib/pact_broker/client/base_client.rb
243
+ - lib/pact_broker/client/base_command.rb
229
244
  - lib/pact_broker/client/can_i_deploy.rb
230
245
  - lib/pact_broker/client/cli/broker.rb
231
246
  - lib/pact_broker/client/cli/can_i_deploy_long_desc.txt
232
247
  - lib/pact_broker/client/cli/create_or_update_webhook_long_desc.txt
233
248
  - lib/pact_broker/client/cli/create_webhook_long_desc.txt
234
249
  - lib/pact_broker/client/cli/custom_thor.rb
250
+ - lib/pact_broker/client/cli/environment_commands.rb
251
+ - lib/pact_broker/client/cli/pacticipant_commands.rb
235
252
  - lib/pact_broker/client/cli/record_deployment_long_desc.txt
236
253
  - lib/pact_broker/client/cli/version_selector_options_parser.rb
237
254
  - lib/pact_broker/client/colorize_notices.rb
238
255
  - lib/pact_broker/client/command_result.rb
239
256
  - lib/pact_broker/client/create_tag.rb
257
+ - lib/pact_broker/client/environments.rb
258
+ - lib/pact_broker/client/environments/create_environment.rb
259
+ - lib/pact_broker/client/environments/delete_environment.rb
260
+ - lib/pact_broker/client/environments/describe_environment.rb
261
+ - lib/pact_broker/client/environments/environment_command.rb
262
+ - lib/pact_broker/client/environments/list_environments.rb
263
+ - lib/pact_broker/client/environments/text_formatter.rb
264
+ - lib/pact_broker/client/environments/update_environment.rb
240
265
  - lib/pact_broker/client/error.rb
266
+ - lib/pact_broker/client/generate_display_name.rb
241
267
  - lib/pact_broker/client/git.rb
242
268
  - lib/pact_broker/client/hal.rb
243
269
  - lib/pact_broker/client/hal/authorization_header_redactor.rb
@@ -260,11 +286,14 @@ files:
260
286
  - lib/pact_broker/client/pact_hash.rb
261
287
  - lib/pact_broker/client/pacticipants.rb
262
288
  - lib/pact_broker/client/pacticipants/create.rb
289
+ - lib/pact_broker/client/pacticipants/list.rb
290
+ - lib/pact_broker/client/pacticipants/text_formatter.rb
263
291
  - lib/pact_broker/client/pacts.rb
264
292
  - lib/pact_broker/client/pacts/list_latest_versions.rb
265
293
  - lib/pact_broker/client/publish_pacts.rb
266
294
  - lib/pact_broker/client/publish_pacts_the_old_way.rb
267
295
  - lib/pact_broker/client/retry.rb
296
+ - lib/pact_broker/client/string_refinements.rb
268
297
  - lib/pact_broker/client/tasks.rb
269
298
  - lib/pact_broker/client/tasks/publication_task.rb
270
299
  - lib/pact_broker/client/version.rb
@@ -288,6 +317,8 @@ files:
288
317
  - script/release.sh
289
318
  - script/trigger-release.sh
290
319
  - spec/fixtures/approvals/can_i_deploy_ignore.approved.txt
320
+ - spec/fixtures/approvals/describe_environment.approved.txt
321
+ - spec/fixtures/approvals/list_environments.approved.txt
291
322
  - spec/fixtures/foo-bar.json
292
323
  - spec/integration/can_i_deploy_spec.rb
293
324
  - spec/integration/create_version_tag_spec.rb
@@ -300,6 +331,10 @@ files:
300
331
  - spec/lib/pact_broker/client/cli/broker_run_webhook_commands_spec.rb
301
332
  - spec/lib/pact_broker/client/cli/custom_thor_spec.rb
302
333
  - spec/lib/pact_broker/client/cli/version_selector_options_parser_spec.rb
334
+ - spec/lib/pact_broker/client/environments/delete_environment_spec.rb
335
+ - spec/lib/pact_broker/client/environments/describe_environment_spec.rb
336
+ - spec/lib/pact_broker/client/environments/update_environment_spec.rb
337
+ - spec/lib/pact_broker/client/generate_display_name_spec.rb
303
338
  - spec/lib/pact_broker/client/git_spec.rb
304
339
  - spec/lib/pact_broker/client/hal/authorization_header_redactor_spec.rb
305
340
  - spec/lib/pact_broker/client/hal/entity_spec.rb
@@ -320,7 +355,9 @@ files:
320
355
  - spec/lib/pact_broker/client/versions_spec.rb
321
356
  - spec/lib/pact_broker/client/webhooks/create_spec.rb
322
357
  - spec/pacts/pact_broker_client-pact_broker.json
358
+ - spec/service_providers/create_environment_spec.rb
323
359
  - spec/service_providers/extra_goodies_spec.rb
360
+ - spec/service_providers/list_environments_spec.rb
324
361
  - spec/service_providers/list_latest_pact_versions_spec.rb.bak
325
362
  - spec/service_providers/pact_broker_client_create_version_spec.rb
326
363
  - spec/service_providers/pact_broker_client_matrix_ignore_spec.rb
@@ -370,12 +407,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
370
407
  - !ruby/object:Gem::Version
371
408
  version: '0'
372
409
  requirements: []
373
- rubygems_version: 3.2.17
410
+ rubygems_version: 3.2.18
374
411
  signing_key:
375
412
  specification_version: 4
376
413
  summary: See description
377
414
  test_files:
378
415
  - spec/fixtures/approvals/can_i_deploy_ignore.approved.txt
416
+ - spec/fixtures/approvals/describe_environment.approved.txt
417
+ - spec/fixtures/approvals/list_environments.approved.txt
379
418
  - spec/fixtures/foo-bar.json
380
419
  - spec/integration/can_i_deploy_spec.rb
381
420
  - spec/integration/create_version_tag_spec.rb
@@ -388,6 +427,10 @@ test_files:
388
427
  - spec/lib/pact_broker/client/cli/broker_run_webhook_commands_spec.rb
389
428
  - spec/lib/pact_broker/client/cli/custom_thor_spec.rb
390
429
  - spec/lib/pact_broker/client/cli/version_selector_options_parser_spec.rb
430
+ - spec/lib/pact_broker/client/environments/delete_environment_spec.rb
431
+ - spec/lib/pact_broker/client/environments/describe_environment_spec.rb
432
+ - spec/lib/pact_broker/client/environments/update_environment_spec.rb
433
+ - spec/lib/pact_broker/client/generate_display_name_spec.rb
391
434
  - spec/lib/pact_broker/client/git_spec.rb
392
435
  - spec/lib/pact_broker/client/hal/authorization_header_redactor_spec.rb
393
436
  - spec/lib/pact_broker/client/hal/entity_spec.rb
@@ -408,7 +451,9 @@ test_files:
408
451
  - spec/lib/pact_broker/client/versions_spec.rb
409
452
  - spec/lib/pact_broker/client/webhooks/create_spec.rb
410
453
  - spec/pacts/pact_broker_client-pact_broker.json
454
+ - spec/service_providers/create_environment_spec.rb
411
455
  - spec/service_providers/extra_goodies_spec.rb
456
+ - spec/service_providers/list_environments_spec.rb
412
457
  - spec/service_providers/list_latest_pact_versions_spec.rb.bak
413
458
  - spec/service_providers/pact_broker_client_create_version_spec.rb
414
459
  - spec/service_providers/pact_broker_client_matrix_ignore_spec.rb