pact_broker-client 1.39.0 → 1.44.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +21 -0
  3. data/.gitignore +1 -0
  4. data/CHANGELOG.md +52 -0
  5. data/Gemfile +4 -0
  6. data/README.md +39 -18
  7. data/doc/pacts/markdown/Pact Broker Client - Pact Broker.md +79 -280
  8. data/lib/pact_broker/client/backports.rb +9 -0
  9. data/lib/pact_broker/client/base_command.rb +95 -0
  10. data/lib/pact_broker/client/can_i_deploy.rb +20 -3
  11. data/lib/pact_broker/client/cli/broker.rb +20 -75
  12. data/lib/pact_broker/client/cli/custom_thor.rb +12 -0
  13. data/lib/pact_broker/client/cli/deployment_commands.rb +74 -0
  14. data/lib/pact_broker/client/cli/environment_commands.rb +70 -0
  15. data/lib/pact_broker/client/cli/pacticipant_commands.rb +53 -0
  16. data/lib/pact_broker/client/cli/record_deployment_long_desc.txt +0 -55
  17. data/lib/pact_broker/client/cli/version_selector_options_parser.rb +4 -0
  18. data/lib/pact_broker/client/colorize_notices.rb +31 -0
  19. data/lib/pact_broker/client/deployments.rb +4 -0
  20. data/lib/pact_broker/client/deployments/record_deployment.rb +38 -0
  21. data/lib/pact_broker/client/deployments/record_release.rb +99 -0
  22. data/lib/pact_broker/client/deployments/record_undeployment.rb +120 -0
  23. data/lib/pact_broker/client/describe_text_formatter.rb +23 -0
  24. data/lib/pact_broker/client/environments.rb +6 -0
  25. data/lib/pact_broker/client/environments/create_environment.rb +31 -0
  26. data/lib/pact_broker/client/environments/delete_environment.rb +27 -0
  27. data/lib/pact_broker/client/environments/describe_environment.rb +26 -0
  28. data/lib/pact_broker/client/environments/environment_command.rb +66 -0
  29. data/lib/pact_broker/client/environments/list_environments.rb +30 -0
  30. data/lib/pact_broker/client/environments/text_formatter.rb +30 -0
  31. data/lib/pact_broker/client/environments/update_environment.rb +31 -0
  32. data/lib/pact_broker/client/generate_display_name.rb +27 -0
  33. data/lib/pact_broker/client/hal/entity.rb +14 -4
  34. data/lib/pact_broker/client/hal/http_client.rb +8 -2
  35. data/lib/pact_broker/client/hal/link.rb +8 -0
  36. data/lib/pact_broker/client/hal_client_methods.rb +1 -3
  37. data/lib/pact_broker/client/matrix.rb +4 -0
  38. data/lib/pact_broker/client/matrix/abbreviate_version_number.rb +15 -0
  39. data/lib/pact_broker/client/matrix/resource.rb +26 -1
  40. data/lib/pact_broker/client/matrix/text_formatter.rb +28 -17
  41. data/lib/pact_broker/client/pacticipants.rb +6 -0
  42. data/lib/pact_broker/client/pacticipants/create.rb +24 -34
  43. data/lib/pact_broker/client/pacticipants/describe.rb +33 -0
  44. data/lib/pact_broker/client/pacticipants/list.rb +34 -0
  45. data/lib/pact_broker/client/pacticipants/text_formatter.rb +41 -0
  46. data/lib/pact_broker/client/publish_pacts.rb +7 -3
  47. data/lib/pact_broker/client/string_refinements.rb +56 -0
  48. data/lib/pact_broker/client/version.rb +1 -1
  49. data/lib/pact_broker/client/versions.rb +4 -1
  50. data/lib/pact_broker/client/versions/describe.rb +3 -1
  51. data/lib/pact_broker/client/versions/formatter.rb +3 -1
  52. data/lib/pact_broker/client/versions/json_formatter.rb +5 -3
  53. data/lib/pact_broker/client/versions/text_formatter.rb +3 -1
  54. data/pact-broker-client.gemspec +2 -0
  55. data/script/approve-all.sh +6 -0
  56. data/script/publish-pact.sh +24 -6
  57. data/script/record-deployments-and-releases.sh +10 -0
  58. data/spec/fixtures/approvals/can_i_deploy_ignore.approved.txt +13 -0
  59. data/spec/fixtures/approvals/describe_environment.approved.txt +7 -0
  60. data/spec/fixtures/approvals/describe_pacticipant.approved.txt +2 -0
  61. data/spec/fixtures/approvals/list_environments.approved.txt +3 -0
  62. data/spec/integration/describe_environment_spec.rb +31 -0
  63. data/spec/lib/pact_broker/client/can_i_deploy_spec.rb +47 -5
  64. data/spec/lib/pact_broker/client/cli/broker_can_i_deploy_spec.rb +5 -5
  65. data/spec/lib/pact_broker/client/cli/broker_publish_spec.rb +1 -1
  66. data/spec/lib/pact_broker/client/cli/broker_run_webhook_commands_spec.rb +3 -3
  67. data/spec/lib/pact_broker/client/cli/version_selector_options_parser_spec.rb +21 -0
  68. data/spec/lib/pact_broker/client/deployments/record_deployment_spec.rb +204 -0
  69. data/spec/lib/pact_broker/client/environments/delete_environment_spec.rb +120 -0
  70. data/spec/lib/pact_broker/client/environments/describe_environment_spec.rb +89 -0
  71. data/spec/lib/pact_broker/client/environments/update_environment_spec.rb +167 -0
  72. data/spec/lib/pact_broker/client/generate_display_name_spec.rb +39 -0
  73. data/spec/lib/pact_broker/client/hal/entity_spec.rb +2 -2
  74. data/spec/lib/pact_broker/client/pacticipants/create_spec.rb +2 -2
  75. data/spec/pacts/pact_broker_client-pact_broker.json +88 -287
  76. data/spec/service_providers/create_environment_spec.rb +78 -0
  77. data/spec/service_providers/list_environments_spec.rb +77 -0
  78. data/spec/service_providers/pact_broker_client_matrix_ignore_spec.rb +98 -0
  79. data/spec/service_providers/pacticipants_create_spec.rb +5 -4
  80. data/spec/service_providers/publish_pacts_spec.rb +5 -2
  81. data/spec/service_providers/record_deployment_spec.rb +17 -36
  82. data/spec/service_providers/record_release_spec.rb +135 -0
  83. data/spec/spec_helper.rb +15 -2
  84. data/spec/support/approvals.rb +26 -0
  85. data/spec/support/shared_context.rb +6 -2
  86. data/tasks/pact.rake +19 -1
  87. metadata +93 -7
  88. data/lib/pact_broker/client/versions/record_deployment.rb +0 -109
  89. data/lib/pact_broker/client/versions/record_undeployment.rb +0 -102
  90. data/spec/lib/pact_broker/client/versions/record_deployment_spec.rb +0 -82
@@ -0,0 +1,120 @@
1
+ require 'pact_broker/client/environments/delete_environment'
2
+
3
+ module PactBroker
4
+ module Client
5
+ module Environments
6
+ describe DeleteEnvironment do
7
+ before do
8
+ allow_any_instance_of(PactBroker::Client::Hal::HttpClient).to receive(:sleep)
9
+ allow_any_instance_of(PactBroker::Client::Hal::HttpClient).to receive(:default_max_tries).and_return(1)
10
+ end
11
+
12
+ let(:params) do
13
+ {
14
+ uuid: uuid,
15
+ name: "new name",
16
+ displayName: "new display name",
17
+ production: false,
18
+ output: output
19
+ }
20
+ end
21
+ let(:options) do
22
+ {
23
+ output: output,
24
+ verbose: verbose
25
+ }
26
+ end
27
+ let(:uuid) { "a9aa4c22-66bb-45d3-ba4c-4916ac8b48c5" }
28
+ let(:pact_broker_base_url) { "http://example.org" }
29
+ let(:pact_broker_client_options) { { pact_broker_base_url: pact_broker_base_url } }
30
+ let(:response_headers) { { "Content-Type" => "application/hal+json"} }
31
+ let(:output) { "text" }
32
+ let(:verbose) { false }
33
+
34
+ before do
35
+ stub_request(:get, "http://example.org/").to_return(status: 200, body: index_response_body, headers: response_headers)
36
+ stub_request(:get, "http://example.org/environments/#{uuid}").to_return(status: get_environment_response_status, body: get_environment_response_body, headers: response_headers)
37
+ stub_request(:delete, "http://example.org/environments/#{uuid}").to_return(status: delete_response_status, body: delete_environment_response_body, headers: response_headers)
38
+ end
39
+ let(:delete_response_status) { 200 }
40
+ let(:get_environment_response_status) { 200 }
41
+
42
+ let(:index_response_body) do
43
+ {
44
+ "_links" => {
45
+ "pb:environments" => {},
46
+ "pb:environment" => {
47
+ "href" => "http://example.org/environments/{uuid}"
48
+ }
49
+ }
50
+ }.to_json
51
+ end
52
+
53
+ let(:get_environment_response_body) do
54
+ {
55
+ name: "existing name",
56
+ displayName: "existing display name",
57
+ production: true
58
+ }.to_json
59
+ end
60
+
61
+ let(:delete_environment_response_body) do
62
+ JSON.parse(get_environment_response_body).merge("updatedAt" => "2021-05-28T13:34:54+10:00").to_json
63
+ end
64
+
65
+ subject { DeleteEnvironment.call(params, options, pact_broker_client_options) }
66
+
67
+ context "when delete is successful" do
68
+ its(:success) { is_expected.to be true }
69
+ its(:message) { is_expected.to include "Deleted environment existing name from the Pact Broker" }
70
+
71
+ context "when output is json" do
72
+ let(:output) { "json" }
73
+
74
+ its(:message) { is_expected.to eq delete_environment_response_body }
75
+ end
76
+ end
77
+
78
+ context "when environments are not supported" do
79
+ let(:index_response_body) { "{}" }
80
+
81
+ its(:success) { is_expected.to be false }
82
+ its(:message) { is_expected.to include "does not support environments" }
83
+ end
84
+
85
+ context "when the environment does not exist" do
86
+ let(:get_environment_response_status) { 404 }
87
+ let(:get_environment_response_body) { "" }
88
+ let(:delete_environment_response_body) { "" }
89
+
90
+ its(:success) { is_expected.to be false }
91
+ its(:message) { is_expected.to include get_environment_response_body }
92
+
93
+ context "when output is json" do
94
+ let(:output) { "json" }
95
+
96
+ its(:message) { is_expected.to eq "{}" }
97
+ end
98
+ end
99
+
100
+ context "when delete is unsuccessful" do
101
+ let(:delete_response_status) { 500 }
102
+ let(:delete_environment_response_body) do
103
+ {
104
+ "some" => "error"
105
+ }.to_json
106
+ end
107
+
108
+ its(:success) { is_expected.to be false }
109
+ its(:message) { is_expected.to include delete_environment_response_body }
110
+
111
+ context "when output is json" do
112
+ let(:output) { "json" }
113
+
114
+ its(:message) { is_expected.to eq delete_environment_response_body }
115
+ end
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,89 @@
1
+ require 'pact_broker/client/environments/describe_environment'
2
+
3
+ module PactBroker
4
+ module Client
5
+ module Environments
6
+ describe DescribeEnvironment do
7
+ before do
8
+ allow_any_instance_of(PactBroker::Client::Hal::HttpClient).to receive(:sleep)
9
+ allow_any_instance_of(PactBroker::Client::Hal::HttpClient).to receive(:default_max_tries).and_return(1)
10
+ end
11
+
12
+ let(:params) { { uuid: uuid } }
13
+ let(:options) { { output: output }}
14
+ let(:uuid) { "a9aa4c22-66bb-45d3-ba4c-4916ac8b48c5" }
15
+ let(:pact_broker_base_url) { "http://example.org" }
16
+ let(:pact_broker_client_options) { { pact_broker_base_url: pact_broker_base_url } }
17
+ let(:response_headers) { { "Content-Type" => "application/hal+json"} }
18
+ let(:output) { "text" }
19
+
20
+ before do
21
+ stub_request(:get, "http://example.org/").to_return(status: 200, body: index_response_body, headers: response_headers)
22
+ stub_request(:get, "http://example.org/environments/#{uuid}").to_return(status: get_environment_response_status, body: get_environment_response_body, headers: response_headers)
23
+ end
24
+
25
+ let(:get_environment_response_status) { 200 }
26
+ let(:index_response_body) do
27
+ {
28
+ "_links" => {
29
+ "pb:environments" => {},
30
+ "pb:environment" => {
31
+ "href" => "http://example.org/environments/{uuid}"
32
+ }
33
+ }
34
+ }.to_json
35
+ end
36
+
37
+ let(:get_environment_response_body) do
38
+ {
39
+ name: "existing name",
40
+ displayName: "existing display name",
41
+ production: true,
42
+ contacts: [
43
+ name: "Someone",
44
+ details: { emailAddress: "foo@bar.com" }
45
+ ]
46
+ }.to_json
47
+ end
48
+
49
+ subject { DescribeEnvironment.call(params, options, pact_broker_client_options) }
50
+
51
+ context "when the environment exists" do
52
+ its(:success) { is_expected.to be true }
53
+
54
+ it "describes the environment" do
55
+ Approvals.verify(subject.message, :name => "describe_environment", format: :txt)
56
+ end
57
+
58
+ context "when output is json" do
59
+ let(:output) { "json" }
60
+
61
+ its(:message) { is_expected.to eq get_environment_response_body }
62
+ end
63
+ end
64
+
65
+ context "when environments are not supported" do
66
+ let(:index_response_body) { "{}" }
67
+
68
+ its(:success) { is_expected.to be false }
69
+ its(:message) { is_expected.to include "does not support environments" }
70
+ end
71
+
72
+ context "when the environment does not exist" do
73
+ let(:get_environment_response_status) { 404 }
74
+ let(:get_environment_response_body) { "" }
75
+ let(:put_environment_response_body) { "" }
76
+
77
+ its(:success) { is_expected.to be false }
78
+ its(:message) { is_expected.to include get_environment_response_body }
79
+
80
+ context "when output is json" do
81
+ let(:output) { "json" }
82
+
83
+ its(:message) { is_expected.to eq "{}" }
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,167 @@
1
+ require 'pact_broker/client/environments/update_environment'
2
+
3
+ module PactBroker
4
+ module Client
5
+ module Environments
6
+ describe UpdateEnvironment do
7
+ before do
8
+ allow_any_instance_of(PactBroker::Client::Hal::HttpClient).to receive(:sleep)
9
+ allow_any_instance_of(PactBroker::Client::Hal::HttpClient).to receive(:default_max_tries).and_return(1)
10
+ end
11
+
12
+ let(:params) do
13
+ {
14
+ uuid: uuid,
15
+ name: "new name",
16
+ display_name: "new display name",
17
+ production: false
18
+ }
19
+ end
20
+ let(:options) do
21
+ {
22
+ output: output,
23
+ verbose: verbose
24
+ }
25
+ end
26
+ let(:uuid) { "a9aa4c22-66bb-45d3-ba4c-4916ac8b48c5" }
27
+ let(:pact_broker_base_url) { "http://example.org" }
28
+ let(:pact_broker_client_options) { { pact_broker_base_url: pact_broker_base_url } }
29
+ let(:response_headers) { { "Content-Type" => "application/hal+json"} }
30
+ let(:output) { "text" }
31
+ let(:verbose) { false }
32
+
33
+ before do
34
+ stub_request(:get, "http://example.org/").to_return(status: 200, body: index_response_body, headers: response_headers)
35
+ stub_request(:get, "http://example.org/environments/#{uuid}").to_return(status: get_environment_response_status, body: get_environment_response_body, headers: response_headers)
36
+ stub_request(:put, "http://example.org/environments/#{uuid}").to_return(status: put_response_status, body: put_environment_response_body, headers: response_headers)
37
+ end
38
+ let(:put_response_status) { 200 }
39
+ let(:get_environment_response_status) { 200 }
40
+ let(:put_request_body) do
41
+ {
42
+ name: "new name",
43
+ displayName: "new display name",
44
+ production: false
45
+ }.to_json
46
+ end
47
+
48
+ let(:index_response_body) do
49
+ {
50
+ "_links" => {
51
+ "pb:environments" => {},
52
+ "pb:environment" => {
53
+ "href" => "http://example.org/environments/{uuid}"
54
+ }
55
+ }
56
+ }.to_json
57
+ end
58
+
59
+ let(:get_environment_response_body) do
60
+ {
61
+ name: "existing name",
62
+ displayName: "existing display name",
63
+ production: true
64
+ }.to_json
65
+ end
66
+
67
+ let(:put_environment_response_body) do
68
+ JSON.parse(get_environment_response_body).merge("updatedAt" => "2021-05-28T13:34:54+10:00").to_json
69
+ end
70
+
71
+ subject { UpdateEnvironment.call(params, options, pact_broker_client_options) }
72
+
73
+ it "updates the environment" do
74
+ request = stub_request(:put, "http://example.org/environments/#{uuid}").with(body: put_request_body)
75
+ subject
76
+ expect(request).to have_been_made
77
+ end
78
+
79
+ context "when update is successful" do
80
+ its(:success) { is_expected.to be true }
81
+ its(:message) { is_expected.to include "Updated new name environment in the Pact Broker" }
82
+
83
+ context "when output is json" do
84
+ let(:output) { "json" }
85
+
86
+ its(:message) { is_expected.to eq put_environment_response_body }
87
+ end
88
+ end
89
+
90
+ context "when environments are not supported" do
91
+ let(:index_response_body) { "{}" }
92
+
93
+ its(:success) { is_expected.to be false }
94
+ its(:message) { is_expected.to include "does not support environments" }
95
+ end
96
+
97
+ context "when a StandardError occurs" do
98
+ before do
99
+ allow_any_instance_of(described_class).to receive(:do_call).and_raise(StandardError.new("Foo"))
100
+ end
101
+
102
+ its(:success) { is_expected.to be false }
103
+ its(:message) { is_expected.to include "StandardError - Foo" }
104
+
105
+ context "when verbose is on" do
106
+ let(:verbose) { true }
107
+
108
+ it "includes the message and class and backtrace in the error" do
109
+ expect(subject.message.split("\n").size).to be > 2
110
+ end
111
+ end
112
+
113
+ context "when output is json" do
114
+ let(:output) { "json" }
115
+
116
+ it "includes the message and class in the error" do
117
+ message_hash = JSON.parse(subject.message)
118
+ expect(message_hash).to eq "error" => { "message" => "Foo", "class" => "StandardError" }
119
+ end
120
+
121
+ context "when verbose is on" do
122
+ let(:verbose) { true }
123
+
124
+ it "includes the message and class and backtrace in the error" do
125
+ message_hash = JSON.parse(subject.message)
126
+ expect(message_hash["error"]["backtrace"]).to be_a(Array)
127
+ end
128
+ end
129
+ end
130
+ end
131
+
132
+ context "when the environment does not exist" do
133
+ let(:get_environment_response_status) { 404 }
134
+ let(:get_environment_response_body) { "" }
135
+ let(:put_environment_response_body) { "" }
136
+
137
+ its(:success) { is_expected.to be false }
138
+ its(:message) { is_expected.to include get_environment_response_body }
139
+
140
+ context "when output is json" do
141
+ let(:output) { "json" }
142
+
143
+ its(:message) { is_expected.to eq "{}" }
144
+ end
145
+ end
146
+
147
+ context "when update is unsuccessful" do
148
+ let(:put_response_status) { 400 }
149
+ let(:put_environment_response_body) do
150
+ {
151
+ "some" => "error"
152
+ }.to_json
153
+ end
154
+
155
+ its(:success) { is_expected.to be false }
156
+ its(:message) { is_expected.to include put_environment_response_body }
157
+
158
+ context "when output is json" do
159
+ let(:output) { "json" }
160
+
161
+ its(:message) { is_expected.to eq put_environment_response_body }
162
+ end
163
+ end
164
+ end
165
+ end
166
+ end
167
+ end
@@ -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