pact_broker-client 1.75.2 → 1.75.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +10 -0
  3. data/lib/pact_broker/client/version.rb +1 -1
  4. metadata +19 -216
  5. data/.github/workflows/test.yml +0 -59
  6. data/.rspec +0 -3
  7. data/lib/pact_broker/client/pacts/list_latest_versions.rb +0 -66
  8. data/lib/pact_broker/client/webhooks/test.rb +0 -16
  9. data/pact-broker-client.gemspec +0 -30
  10. data/spec/fixtures/MyConsumer-MyProvider (1).json +0 -37
  11. data/spec/fixtures/MyConsumer-MyProvider.json +0 -37
  12. data/spec/fixtures/approvals/can_i_deploy_failure_dry_run.approved.txt +0 -7
  13. data/spec/fixtures/approvals/can_i_deploy_ignore.approved.txt +0 -13
  14. data/spec/fixtures/approvals/can_i_deploy_success_dry_run.approved.txt +0 -7
  15. data/spec/fixtures/approvals/describe_environment.approved.txt +0 -7
  16. data/spec/fixtures/approvals/describe_pacticipant.approved.txt +0 -2
  17. data/spec/fixtures/approvals/list_environments.approved.txt +0 -3
  18. data/spec/fixtures/approvals/publish_provider_contract.approved.txt +0 -2
  19. data/spec/fixtures/certificates/ca_cert.pem +0 -19
  20. data/spec/fixtures/certificates/ca_cert.srl +0 -1
  21. data/spec/fixtures/certificates/ca_key.pem +0 -28
  22. data/spec/fixtures/certificates/client_cert.pem +0 -17
  23. data/spec/fixtures/certificates/key.pem +0 -28
  24. data/spec/fixtures/certificates/server.csr +0 -15
  25. data/spec/fixtures/certificates/unsigned_cert.pem +0 -19
  26. data/spec/fixtures/certificates/unsigned_key.pem +0 -28
  27. data/spec/fixtures/foo-bar.json +0 -31
  28. data/spec/integration/can_i_deploy_spec.rb +0 -24
  29. data/spec/integration/can_i_merge_spec.rb +0 -44
  30. data/spec/integration/create_version_tag_spec.rb +0 -20
  31. data/spec/integration/describe_environment_spec.rb +0 -31
  32. data/spec/integration/publish_provider_contract_spec.rb +0 -53
  33. data/spec/integration/unknown_options_spec.rb +0 -39
  34. data/spec/lib/pact_broker/client/base_client_spec.rb +0 -182
  35. data/spec/lib/pact_broker/client/branches/delete_branch_spec.rb +0 -103
  36. data/spec/lib/pact_broker/client/can_i_deploy_spec.rb +0 -250
  37. data/spec/lib/pact_broker/client/cli/broker_can_i_deploy_spec.rb +0 -196
  38. data/spec/lib/pact_broker/client/cli/broker_create_or_update_webhook_spec.rb +0 -23
  39. data/spec/lib/pact_broker/client/cli/broker_create_webhook_spec.rb +0 -23
  40. data/spec/lib/pact_broker/client/cli/broker_publish_spec.rb +0 -327
  41. data/spec/lib/pact_broker/client/cli/broker_run_webhook_commands_spec.rb +0 -287
  42. data/spec/lib/pact_broker/client/cli/custom_thor_spec.rb +0 -174
  43. data/spec/lib/pact_broker/client/cli/version_selector_options_parser_spec.rb +0 -97
  44. data/spec/lib/pact_broker/client/deployments/record_deployment_spec.rb +0 -224
  45. data/spec/lib/pact_broker/client/deployments/record_support_ended_spec.rb +0 -208
  46. data/spec/lib/pact_broker/client/deployments/record_undeployment_spec.rb +0 -227
  47. data/spec/lib/pact_broker/client/environments/delete_environment_spec.rb +0 -120
  48. data/spec/lib/pact_broker/client/environments/describe_environment_spec.rb +0 -89
  49. data/spec/lib/pact_broker/client/environments/update_environment_spec.rb +0 -167
  50. data/spec/lib/pact_broker/client/generate_display_name_spec.rb +0 -39
  51. data/spec/lib/pact_broker/client/git_spec.rb +0 -159
  52. data/spec/lib/pact_broker/client/hal/authorization_header_redactor_spec.rb +0 -17
  53. data/spec/lib/pact_broker/client/hal/entity_spec.rb +0 -149
  54. data/spec/lib/pact_broker/client/hal/http_client_spec.rb +0 -238
  55. data/spec/lib/pact_broker/client/hal/link_spec.rb +0 -127
  56. data/spec/lib/pact_broker/client/matrix/abbreviate_version_number_spec.rb +0 -42
  57. data/spec/lib/pact_broker/client/matrix/resource_spec.rb +0 -70
  58. data/spec/lib/pact_broker/client/matrix/text_formatter_spec.rb +0 -63
  59. data/spec/lib/pact_broker/client/matrix_spec.rb +0 -17
  60. data/spec/lib/pact_broker/client/merge_pacts_spec.rb +0 -198
  61. data/spec/lib/pact_broker/client/pact_broker_client_spec.rb +0 -47
  62. data/spec/lib/pact_broker/client/pacticipants/create_spec.rb +0 -31
  63. data/spec/lib/pact_broker/client/pacticipants_spec.rb +0 -18
  64. data/spec/lib/pact_broker/client/publish_pacts_the_old_way_spec.rb +0 -272
  65. data/spec/lib/pact_broker/client/retry_spec.rb +0 -119
  66. data/spec/lib/pact_broker/client/tasks/publication_task_spec.rb +0 -231
  67. data/spec/lib/pact_broker/client/versions/create_spec.rb +0 -174
  68. data/spec/lib/pact_broker/client/versions/describe_spec.rb +0 -64
  69. data/spec/lib/pact_broker/client/versions_spec.rb +0 -34
  70. data/spec/lib/pact_broker/client/webhooks/create_spec.rb +0 -99
  71. data/spec/lib/pactflow/client/provider_contracts/publish_spec.rb +0 -179
  72. data/spec/pacts/pact_broker_client-pact_broker.json +0 -2969
  73. data/spec/pacts/pact_broker_client-pactflow.json +0 -288
  74. data/spec/readme_spec.rb +0 -16
  75. data/spec/service_providers/create_environment_spec.rb +0 -78
  76. data/spec/service_providers/delete_branch_spec.rb +0 -68
  77. data/spec/service_providers/extra_goodies_spec.rb +0 -108
  78. data/spec/service_providers/list_environments_spec.rb +0 -77
  79. data/spec/service_providers/list_latest_pact_versions_spec.rb.bak +0 -44
  80. data/spec/service_providers/pact_broker_client_matrix_ignore_spec.rb +0 -98
  81. data/spec/service_providers/pact_broker_client_matrix_spec.rb +0 -292
  82. data/spec/service_providers/pact_broker_client_pacticipant_version_spec.rb +0 -56
  83. data/spec/service_providers/pact_broker_client_publish_spec.rb +0 -135
  84. data/spec/service_providers/pact_broker_client_register_repository_spec.rb +0 -49
  85. data/spec/service_providers/pact_broker_client_retrieve_all_pacts_for_provider_spec.rb +0 -53
  86. data/spec/service_providers/pact_broker_client_retrieve_pact_spec.rb +0 -109
  87. data/spec/service_providers/pact_broker_client_tags_spec.rb +0 -101
  88. data/spec/service_providers/pact_broker_client_versions_spec.rb +0 -113
  89. data/spec/service_providers/pact_helper.rb +0 -136
  90. data/spec/service_providers/pactflow_publish_provider_contract_spec.rb +0 -137
  91. data/spec/service_providers/pactflow_publish_provider_contract_the_old_way_spec.rb +0 -129
  92. data/spec/service_providers/pactflow_webhooks_create_spec.rb +0 -86
  93. data/spec/service_providers/pacticipants_create_spec.rb +0 -119
  94. data/spec/service_providers/publish_pacts_spec.rb +0 -114
  95. data/spec/service_providers/record_deployment_spec.rb +0 -199
  96. data/spec/service_providers/record_release_spec.rb +0 -130
  97. data/spec/service_providers/record_undeployment_spec.rb +0 -164
  98. data/spec/service_providers/webhooks_create_spec.rb +0 -391
  99. data/spec/spec_helper.rb +0 -68
  100. data/spec/support/approvals.rb +0 -26
  101. data/spec/support/cli_test_pacts/bar.json +0 -0
  102. data/spec/support/cli_test_pacts/foo.json +0 -0
  103. data/spec/support/latest_pacts_for_provider.json +0 -15
  104. data/spec/support/matrix.json +0 -35
  105. data/spec/support/matrix.txt +0 -3
  106. data/spec/support/matrix_error.txt +0 -3
  107. data/spec/support/matrix_with_results.txt +0 -10
  108. data/spec/support/pacticipant_get.json +0 -18
  109. data/spec/support/pacticipants_list.json +0 -26
  110. data/spec/support/pacts_latest_list.json +0 -41
  111. data/spec/support/shared_context.rb +0 -25
  112. data/spec/support/ssl_server.rb +0 -42
@@ -1,208 +0,0 @@
1
- require 'pact_broker/client/deployments/record_support_ended'
2
-
3
- module PactBroker
4
- module Client
5
- module Deployments
6
- describe RecordSupportEnded do
7
- let(:params) do
8
- {
9
- pacticipant_name: "Foo",
10
- version_number: version_number,
11
- environment_name: "test"
12
- }
13
- end
14
- let(:version_number) { "2" }
15
- let(:output) { "text" }
16
- let(:options) { { output: output, verbose: true } }
17
- let(:pact_broker_base_url) { "http://broker" }
18
- let(:pact_broker_client_options) { { pact_broker_base_url: pact_broker_base_url } }
19
-
20
- let(:index_body_hash) do
21
- {
22
- _links: {
23
- :'pb:environments' => {
24
- href: environments_url
25
- },
26
- :'pb:pacticipant' => {
27
- href: pacticipant_url
28
- }
29
- }
30
- }
31
- end
32
-
33
- let(:environments_hash) do
34
- {
35
- _links: {
36
- :'pb:environments' => [
37
- {
38
- name: "test",
39
- href: test_environment_url
40
- }
41
- ]
42
- }
43
- }
44
- end
45
-
46
- let(:environment_hash) do
47
- {
48
- _links: {
49
- :'pb:currently-supported-released-versions' => {
50
- href: currently_supported_versions_url
51
- }
52
- }
53
- }
54
- end
55
-
56
- let(:supported_versions_hash) do
57
- {
58
- _embedded: {
59
- releasedVersions: [
60
- {
61
- number: "customer-1",
62
- _links: {
63
- self: {
64
- href: supported_version_url_1
65
- }
66
- }
67
- },
68
- {
69
- number: returned_target_2,
70
- _links: {
71
- self: {
72
- href: supported_version_url_2
73
- }
74
- }
75
- }
76
- ]
77
- }
78
- }
79
- end
80
-
81
- let(:returned_target_2) { nil }
82
- let(:supported_version_hash) do
83
- {
84
- _embedded: {
85
- version: {
86
- number: "2"
87
- }
88
- }
89
- }
90
- end
91
-
92
- let(:environments_url) { "#{webmock_base_url}/environments" }
93
- let(:test_environment_url) { "#{webmock_base_url}/environments/1234" }
94
- let(:currently_supported_versions_url) { "#{webmock_base_url}/currently-deployed-versions" }
95
- let(:supported_version_url_1) { "#{webmock_base_url}/deployed-version-1" }
96
- let(:supported_version_url_2) { "#{webmock_base_url}/deployed-version-2" }
97
- let(:pacticipant_url) { "#{webmock_base_url}/pacticipant" }
98
-
99
- let(:webmock_base_url) { "http://broker" }
100
-
101
- let!(:index_request) do
102
- stub_request(:get, "http://broker").to_return(status: 200, body: index_body_hash.to_json, headers: { "Content-Type" => "application/hal+json" } )
103
- end
104
-
105
- let!(:environments_request) do
106
- stub_request(:get, "http://broker/environments").to_return(status: 200, body: environments_hash.to_json, headers: { "Content-Type" => "application/hal+json" } )
107
- end
108
-
109
- let!(:environment_request) do
110
- stub_request(:get, test_environment_url).to_return(status: 200, body: environment_hash.to_json, headers: { "Content-Type" => "application/hal+json" } )
111
- end
112
-
113
- let!(:supported_versions_request) do
114
- stub_request(:get, currently_supported_versions_url + "?pacticipant=Foo&version=2").to_return(status: 200, body: supported_versions_hash.to_json, headers: { "Content-Type" => "application/hal+json" } )
115
- end
116
-
117
- let!(:supported_version_patch_request_1) do
118
- stub_request(:patch, supported_version_url_1).with(body: { currentlySupported: false}.to_json).to_return(status: 200, body: supported_version_hash.to_json, headers: { "Content-Type" => "application/hal+json" })
119
- end
120
-
121
- let!(:supported_version_patch_request_2) do
122
- stub_request(:patch, supported_version_url_2).with(body: { currentlySupported: false}.to_json).to_return(status: 200, body: supported_version_hash.to_json, headers: { "Content-Type" => "application/hal+json" })
123
- end
124
-
125
- let!(:pacticipant_request) do
126
- stub_request(:get, pacticipant_url).to_return(status: pacticipant_request_status, body: {}.to_json, headers: { "Content-Type" => "application/hal+json" })
127
- end
128
-
129
- let(:pacticipant_request_status) { 200 }
130
-
131
- subject { RecordSupportEnded.call(params, options, pact_broker_client_options) }
132
-
133
- its(:success) { is_expected.to eq true }
134
- its(:message) { is_expected.to include "Recorded support ended for Foo version 2 in test environment in the Pact Broker" }
135
-
136
- context "when there is no pb:environments relation in the index" do
137
- let(:index_body_hash) do
138
- {
139
- _links: {}
140
- }
141
- end
142
-
143
- its(:success) { is_expected.to be false }
144
- its(:message) { is_expected.to include "support" }
145
- end
146
-
147
- context "when output is json" do
148
- let(:output) { "json" }
149
- its(:message) { is_expected.to eq [supported_version_hash, supported_version_hash].to_json }
150
- end
151
-
152
- context "when there is an error returned from one of the supported version updates (there should only ever be one supported version, but testing just for the sake of it)" do
153
- let!(:supported_version_patch_request_2) do
154
- stub_request(:patch, supported_version_url_2).to_return(status: 400, body: { errors: { foo: ["some error"]}}.to_json, headers: { "Content-Type" => "application/hal+json" })
155
- end
156
-
157
- let(:returned_target_2) { "customer-1" }
158
-
159
- its(:success) { is_expected.to be false }
160
- its(:message) { is_expected.to include "Recorded" }
161
- its(:message) { is_expected.to include "some error" }
162
- end
163
-
164
- context "when there is no currently-deployed-versions relation in the environment resource" do
165
- let(:environment_hash) do
166
- {
167
- _links: {}
168
- }
169
- end
170
-
171
- its(:success) { is_expected.to be false }
172
- its(:message) { is_expected.to include "support" }
173
- end
174
-
175
- context "when there is no matching supported versions" do
176
- let(:supported_versions_hash) do
177
- {
178
- _embedded: {
179
- releasedVersions: []
180
- }
181
- }
182
- end
183
-
184
- let(:expected_message) { "Foo version 2 is not currently released in test environment. Cannot record support ended." }
185
-
186
- its(:success) { is_expected.to be false }
187
- its(:message) { is_expected.to include expected_message }
188
-
189
- context "when there are no supported versions for the pacticipant" do
190
- context "when the pacticipant does not exist" do
191
- let(:pacticipant_request_status) { 404 }
192
-
193
- its(:success) { is_expected.to be false }
194
- its(:message) { is_expected.to include "No pacticipant with name 'Foo' found" }
195
- end
196
- end
197
-
198
- context "when output is json" do
199
- let(:output) { "json" }
200
-
201
- its(:message) { is_expected.to eq({ error: { message: expected_message } }.to_json) }
202
- end
203
- end
204
-
205
- end
206
- end
207
- end
208
- end
@@ -1,227 +0,0 @@
1
- require 'pact_broker/client/deployments/record_undeployment'
2
-
3
- module PactBroker
4
- module Client
5
- module Deployments
6
- describe RecordUndeployment do
7
- let(:params) do
8
- {
9
- pacticipant_name: "Foo",
10
- application_instance: application_instance,
11
- environment_name: "test"
12
- }
13
- end
14
- let(:application_instance) { "customer-1" }
15
- let(:output) { "text" }
16
- let(:options) { { output: output, verbose: true } }
17
- let(:pact_broker_base_url) { "http://broker" }
18
- let(:pact_broker_client_options) { { pact_broker_base_url: pact_broker_base_url } }
19
-
20
- let(:index_body_hash) do
21
- {
22
- _links: {
23
- :'pb:environments' => {
24
- href: environments_url
25
- },
26
- :'pb:pacticipant' => {
27
- href: pacticipant_url
28
- }
29
- }
30
- }
31
- end
32
-
33
- let(:environments_hash) do
34
- {
35
- _links: {
36
- :'pb:environments' => [
37
- {
38
- name: "test",
39
- href: test_environment_url
40
- }
41
- ]
42
- }
43
- }
44
- end
45
-
46
- let(:environment_hash) do
47
- {
48
- _links: {
49
- :'pb:currently-deployed-deployed-versions' => {
50
- href: currently_deployed_versions_url
51
- }
52
- }
53
- }
54
- end
55
-
56
- let(:deployed_versions_hash) do
57
- {
58
- _embedded: {
59
- deployedVersions: [
60
- {
61
- target: "customer-1",
62
- _links: {
63
- self: {
64
- href: deployed_version_url_1
65
- }
66
- }
67
- },
68
- {
69
- target: returned_target_2,
70
- _links: {
71
- self: {
72
- href: deployed_version_url_2
73
- }
74
- }
75
- }
76
- ]
77
- }
78
- }
79
- end
80
-
81
- let(:returned_target_2) { nil }
82
- let(:deployed_version_hash) do
83
- {
84
- _embedded: {
85
- version: {
86
- number: "2"
87
- }
88
- }
89
- }
90
- end
91
-
92
- let(:environments_url) { "#{webmock_base_url}/environments" }
93
- let(:test_environment_url) { "#{webmock_base_url}/environments/1234" }
94
- let(:currently_deployed_versions_url) { "#{webmock_base_url}/currently-deployed-versions" }
95
- let(:deployed_version_url_1) { "#{webmock_base_url}/deployed-version-1" }
96
- let(:deployed_version_url_2) { "#{webmock_base_url}/deployed-version-2" }
97
- let(:pacticipant_url) { "#{webmock_base_url}/pacticipant" }
98
-
99
- let(:webmock_base_url) { "http://broker" }
100
-
101
- let!(:index_request) do
102
- stub_request(:get, "http://broker").to_return(status: 200, body: index_body_hash.to_json, headers: { "Content-Type" => "application/hal+json" } )
103
- end
104
-
105
- let!(:environments_request) do
106
- stub_request(:get, "http://broker/environments").to_return(status: 200, body: environments_hash.to_json, headers: { "Content-Type" => "application/hal+json" } )
107
- end
108
-
109
- let!(:environment_request) do
110
- stub_request(:get, test_environment_url).to_return(status: 200, body: environment_hash.to_json, headers: { "Content-Type" => "application/hal+json" } )
111
- end
112
-
113
- let!(:deployed_versions_request) do
114
- stub_request(:get, currently_deployed_versions_url + "?pacticipant=Foo").to_return(status: 200, body: deployed_versions_hash.to_json, headers: { "Content-Type" => "application/hal+json" } )
115
- end
116
-
117
- let!(:deployed_version_patch_request_1) do
118
- stub_request(:patch, deployed_version_url_1).with(body: { currentlyDeployed: false}.to_json).to_return(status: 200, body: deployed_version_hash.to_json, headers: { "Content-Type" => "application/hal+json" })
119
- end
120
-
121
- let!(:deployed_version_patch_request_2) do
122
- stub_request(:patch, deployed_version_url_2).with(body: { currentlyDeployed: false}.to_json).to_return(status: 200, body: deployed_version_hash.to_json, headers: { "Content-Type" => "application/hal+json" })
123
- end
124
-
125
- let!(:pacticipant_request) do
126
- stub_request(:get, pacticipant_url).to_return(status: pacticipant_request_status, body: {}.to_json, headers: { "Content-Type" => "application/hal+json" })
127
- end
128
-
129
- let(:pacticipant_request_status) { 200 }
130
-
131
- subject { RecordUndeployment.call(params, options, pact_broker_client_options) }
132
-
133
- its(:success) { is_expected.to eq true }
134
- its(:message) { is_expected.to include "Recorded undeployment of Foo version 2 from test environment (application instance customer-1) in the Pact Broker" }
135
-
136
- context "when there is no pb:environments relation in the index" do
137
- let(:index_body_hash) do
138
- {
139
- _links: {}
140
- }
141
- end
142
-
143
- its(:success) { is_expected.to be false }
144
- its(:message) { is_expected.to include "support" }
145
- end
146
-
147
- context "when output is json" do
148
- let(:output) { "json" }
149
- its(:message) { is_expected.to eq [deployed_version_hash].to_json }
150
- end
151
-
152
- context "when there is an error returned from one of the deployed version updates (there should only ever be one deployed version, but testing just for the sake of it)" do
153
- let!(:deployed_version_patch_request_2) do
154
- stub_request(:patch, deployed_version_url_2).to_return(status: 400, body: { errors: { foo: ["some error"]}}.to_json, headers: { "Content-Type" => "application/hal+json" })
155
- end
156
-
157
- let(:returned_target_2) { "customer-1" }
158
-
159
- its(:success) { is_expected.to be false }
160
- its(:message) { is_expected.to include "Recorded undeployment of Foo version 2" }
161
- its(:message) { is_expected.to include "some error" }
162
- end
163
-
164
- context "when there is no currently-deployed-versions relation in the environment resource" do
165
- let(:environment_hash) do
166
- {
167
- _links: {}
168
- }
169
- end
170
-
171
- its(:success) { is_expected.to be false }
172
- its(:message) { is_expected.to include "support" }
173
- end
174
-
175
- context "when a target is provided and there is no deployed version with a matching target" do
176
- let(:application_instance) { "wrong" }
177
- let(:expected_message) { "Foo is not currently deployed to application instance 'wrong' in test environment. Please omit the application instance or specify one of the following application instances to record the undeployment from: customer-1." }
178
-
179
- its(:success) { is_expected.to be false }
180
- its(:message) { is_expected.to include expected_message }
181
-
182
- context "when output is json" do
183
- let(:output) { "json" }
184
-
185
- its(:message) { is_expected.to eq({ error: { message: expected_message } }.to_json) }
186
- end
187
- end
188
-
189
- context "when a target is provided and there is no deployed version with a matching target and all the application instances are set" do
190
- let(:application_instance) { "wrong" }
191
- let(:returned_target_2) { "customer-2" }
192
- let(:expected_message) { "Foo is not currently deployed to application instance 'wrong' in test environment. Please specify one of the following application instances to record the undeployment from: customer-1, customer-2." }
193
-
194
- its(:message) { is_expected.to include expected_message }
195
- end
196
-
197
- context "when a target is not provided and there is no deployed verison without a target" do
198
- let(:application_instance) { nil }
199
- let(:returned_target_2) { "customer-2" }
200
-
201
- its(:success) { is_expected.to be false }
202
- its(:message) { is_expected.to include "Please specify one of the following application instances to record the undeployment from: customer-1, customer-2" }
203
- end
204
-
205
- context "when there are no deployed versions for the pacticipant" do
206
- let(:deployed_versions_hash) do
207
- {
208
- _embedded: {
209
- deployedVersions: []
210
- }
211
- }
212
- end
213
-
214
- its(:success) { is_expected.to be false }
215
- its(:message) { is_expected.to include "Foo is not currently deployed to test environment. Cannot record undeployment." }
216
-
217
- context "when the pacticipant does not exist" do
218
- let(:pacticipant_request_status) { 404 }
219
-
220
- its(:success) { is_expected.to be false }
221
- its(:message) { is_expected.to include "No pacticipant with name 'Foo' found" }
222
- end
223
- end
224
- end
225
- end
226
- end
227
- end
@@ -1,120 +0,0 @@
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
@@ -1,89 +0,0 @@
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