pact_broker-client 1.75.3 → 1.76.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -0
  3. data/lib/pact_broker/client/can_i_deploy.rb +1 -1
  4. data/lib/pact_broker/client/version.rb +1 -1
  5. metadata +5 -216
  6. data/.github/workflows/test.yml +0 -59
  7. data/.rspec +0 -3
  8. data/lib/pact_broker/client/pacts/list_latest_versions.rb +0 -66
  9. data/lib/pact_broker/client/webhooks/test.rb +0 -16
  10. data/pact-broker-client.gemspec +0 -31
  11. data/spec/fixtures/MyConsumer-MyProvider (1).json +0 -37
  12. data/spec/fixtures/MyConsumer-MyProvider.json +0 -37
  13. data/spec/fixtures/approvals/can_i_deploy_failure_dry_run.approved.txt +0 -7
  14. data/spec/fixtures/approvals/can_i_deploy_ignore.approved.txt +0 -13
  15. data/spec/fixtures/approvals/can_i_deploy_success_dry_run.approved.txt +0 -7
  16. data/spec/fixtures/approvals/describe_environment.approved.txt +0 -7
  17. data/spec/fixtures/approvals/describe_pacticipant.approved.txt +0 -2
  18. data/spec/fixtures/approvals/list_environments.approved.txt +0 -3
  19. data/spec/fixtures/approvals/publish_provider_contract.approved.txt +0 -2
  20. data/spec/fixtures/certificates/ca_cert.pem +0 -19
  21. data/spec/fixtures/certificates/ca_cert.srl +0 -1
  22. data/spec/fixtures/certificates/ca_key.pem +0 -28
  23. data/spec/fixtures/certificates/client_cert.pem +0 -17
  24. data/spec/fixtures/certificates/key.pem +0 -28
  25. data/spec/fixtures/certificates/server.csr +0 -15
  26. data/spec/fixtures/certificates/unsigned_cert.pem +0 -19
  27. data/spec/fixtures/certificates/unsigned_key.pem +0 -28
  28. data/spec/fixtures/foo-bar.json +0 -31
  29. data/spec/integration/can_i_deploy_spec.rb +0 -24
  30. data/spec/integration/can_i_merge_spec.rb +0 -44
  31. data/spec/integration/create_version_tag_spec.rb +0 -20
  32. data/spec/integration/describe_environment_spec.rb +0 -31
  33. data/spec/integration/publish_provider_contract_spec.rb +0 -53
  34. data/spec/integration/unknown_options_spec.rb +0 -39
  35. data/spec/lib/pact_broker/client/base_client_spec.rb +0 -182
  36. data/spec/lib/pact_broker/client/branches/delete_branch_spec.rb +0 -103
  37. data/spec/lib/pact_broker/client/can_i_deploy_spec.rb +0 -250
  38. data/spec/lib/pact_broker/client/cli/broker_can_i_deploy_spec.rb +0 -196
  39. data/spec/lib/pact_broker/client/cli/broker_create_or_update_webhook_spec.rb +0 -23
  40. data/spec/lib/pact_broker/client/cli/broker_create_webhook_spec.rb +0 -23
  41. data/spec/lib/pact_broker/client/cli/broker_publish_spec.rb +0 -327
  42. data/spec/lib/pact_broker/client/cli/broker_run_webhook_commands_spec.rb +0 -287
  43. data/spec/lib/pact_broker/client/cli/custom_thor_spec.rb +0 -174
  44. data/spec/lib/pact_broker/client/cli/version_selector_options_parser_spec.rb +0 -97
  45. data/spec/lib/pact_broker/client/deployments/record_deployment_spec.rb +0 -224
  46. data/spec/lib/pact_broker/client/deployments/record_support_ended_spec.rb +0 -208
  47. data/spec/lib/pact_broker/client/deployments/record_undeployment_spec.rb +0 -227
  48. data/spec/lib/pact_broker/client/environments/delete_environment_spec.rb +0 -120
  49. data/spec/lib/pact_broker/client/environments/describe_environment_spec.rb +0 -89
  50. data/spec/lib/pact_broker/client/environments/update_environment_spec.rb +0 -167
  51. data/spec/lib/pact_broker/client/generate_display_name_spec.rb +0 -39
  52. data/spec/lib/pact_broker/client/git_spec.rb +0 -159
  53. data/spec/lib/pact_broker/client/hal/authorization_header_redactor_spec.rb +0 -17
  54. data/spec/lib/pact_broker/client/hal/entity_spec.rb +0 -149
  55. data/spec/lib/pact_broker/client/hal/http_client_spec.rb +0 -238
  56. data/spec/lib/pact_broker/client/hal/link_spec.rb +0 -127
  57. data/spec/lib/pact_broker/client/matrix/abbreviate_version_number_spec.rb +0 -42
  58. data/spec/lib/pact_broker/client/matrix/resource_spec.rb +0 -70
  59. data/spec/lib/pact_broker/client/matrix/text_formatter_spec.rb +0 -63
  60. data/spec/lib/pact_broker/client/matrix_spec.rb +0 -17
  61. data/spec/lib/pact_broker/client/merge_pacts_spec.rb +0 -198
  62. data/spec/lib/pact_broker/client/pact_broker_client_spec.rb +0 -47
  63. data/spec/lib/pact_broker/client/pacticipants/create_spec.rb +0 -31
  64. data/spec/lib/pact_broker/client/pacticipants_spec.rb +0 -18
  65. data/spec/lib/pact_broker/client/publish_pacts_the_old_way_spec.rb +0 -272
  66. data/spec/lib/pact_broker/client/retry_spec.rb +0 -119
  67. data/spec/lib/pact_broker/client/tasks/publication_task_spec.rb +0 -231
  68. data/spec/lib/pact_broker/client/versions/create_spec.rb +0 -174
  69. data/spec/lib/pact_broker/client/versions/describe_spec.rb +0 -64
  70. data/spec/lib/pact_broker/client/versions_spec.rb +0 -34
  71. data/spec/lib/pact_broker/client/webhooks/create_spec.rb +0 -99
  72. data/spec/lib/pactflow/client/provider_contracts/publish_spec.rb +0 -179
  73. data/spec/pacts/pact_broker_client-pact_broker.json +0 -2969
  74. data/spec/pacts/pact_broker_client-pactflow.json +0 -288
  75. data/spec/readme_spec.rb +0 -16
  76. data/spec/service_providers/create_environment_spec.rb +0 -78
  77. data/spec/service_providers/delete_branch_spec.rb +0 -68
  78. data/spec/service_providers/extra_goodies_spec.rb +0 -108
  79. data/spec/service_providers/list_environments_spec.rb +0 -77
  80. data/spec/service_providers/list_latest_pact_versions_spec.rb.bak +0 -44
  81. data/spec/service_providers/pact_broker_client_matrix_ignore_spec.rb +0 -98
  82. data/spec/service_providers/pact_broker_client_matrix_spec.rb +0 -292
  83. data/spec/service_providers/pact_broker_client_pacticipant_version_spec.rb +0 -56
  84. data/spec/service_providers/pact_broker_client_publish_spec.rb +0 -135
  85. data/spec/service_providers/pact_broker_client_register_repository_spec.rb +0 -49
  86. data/spec/service_providers/pact_broker_client_retrieve_all_pacts_for_provider_spec.rb +0 -53
  87. data/spec/service_providers/pact_broker_client_retrieve_pact_spec.rb +0 -109
  88. data/spec/service_providers/pact_broker_client_tags_spec.rb +0 -101
  89. data/spec/service_providers/pact_broker_client_versions_spec.rb +0 -113
  90. data/spec/service_providers/pact_helper.rb +0 -136
  91. data/spec/service_providers/pactflow_publish_provider_contract_spec.rb +0 -137
  92. data/spec/service_providers/pactflow_publish_provider_contract_the_old_way_spec.rb +0 -129
  93. data/spec/service_providers/pactflow_webhooks_create_spec.rb +0 -86
  94. data/spec/service_providers/pacticipants_create_spec.rb +0 -119
  95. data/spec/service_providers/publish_pacts_spec.rb +0 -114
  96. data/spec/service_providers/record_deployment_spec.rb +0 -199
  97. data/spec/service_providers/record_release_spec.rb +0 -130
  98. data/spec/service_providers/record_undeployment_spec.rb +0 -164
  99. data/spec/service_providers/webhooks_create_spec.rb +0 -391
  100. data/spec/spec_helper.rb +0 -68
  101. data/spec/support/approvals.rb +0 -26
  102. data/spec/support/cli_test_pacts/bar.json +0 -0
  103. data/spec/support/cli_test_pacts/foo.json +0 -0
  104. data/spec/support/latest_pacts_for_provider.json +0 -15
  105. data/spec/support/matrix.json +0 -35
  106. data/spec/support/matrix.txt +0 -3
  107. data/spec/support/matrix_error.txt +0 -3
  108. data/spec/support/matrix_with_results.txt +0 -10
  109. data/spec/support/pacticipant_get.json +0 -18
  110. data/spec/support/pacticipants_list.json +0 -26
  111. data/spec/support/pacts_latest_list.json +0 -41
  112. data/spec/support/shared_context.rb +0 -25
  113. data/spec/support/ssl_server.rb +0 -42
@@ -1,327 +0,0 @@
1
- require 'pact_broker/client/cli/broker'
2
- require 'pact_broker/client/publish_pacts'
3
- require 'pact_broker/client/git'
4
- require 'ostruct'
5
-
6
- module PactBroker::Client::CLI
7
- describe Broker do
8
- describe '.broker' do
9
- before do
10
- allow(PactBroker::Client::PublishPacts).to receive(:call).and_return(result)
11
- allow(PactBroker::Client::Git).to receive(:branch).and_return('bar')
12
- allow(PactBroker::Client::Git).to receive(:commit).and_return('6.6.6')
13
- allow(PactBroker::Client::Git).to receive(:build_url).and_return('build_url')
14
- subject.options = OpenStruct.new(minimum_valid_options)
15
- allow($stdout).to receive(:puts)
16
- end
17
-
18
- let(:success) { true }
19
- let(:result) { instance_double(PactBroker::Client::CommandResult, success: success, message: "message")}
20
- let(:file_list) { ["spec/support/cli_test_pacts/foo.json"] }
21
- let(:minimum_valid_options) do
22
- {
23
- pact_dir: 'spec/pacts',
24
- consumer_app_version: '1.2.3',
25
- broker_base_url: 'http://pact-broker'
26
- }
27
- end
28
-
29
- let(:invoke_broker) { subject.publish(*file_list) }
30
-
31
- context "with minimum valid options" do
32
- it "invokes the PublishPacts command" do
33
- expect(PactBroker::Client::PublishPacts).to receive(:call).with(
34
- "http://pact-broker",
35
- ["spec/support/cli_test_pacts/foo.json"],
36
- { number: "1.2.3", tags: [] },
37
- {},
38
- { pact_broker_base_url: 'http://pact-broker' }
39
- )
40
- invoke_broker
41
- end
42
- end
43
-
44
- context "with a file pattern specified" do
45
- let(:file_list) { ["spec/support/cli_test_pacts/*.json"] }
46
-
47
- it "invokes the PublishPacts command with the expanded list of files" do
48
- expect(PactBroker::Client::PublishPacts).to receive(:call).with(
49
- anything,
50
- ["spec/support/cli_test_pacts/bar.json", "spec/support/cli_test_pacts/foo.json"],
51
- anything,
52
- anything,
53
- anything
54
- )
55
- invoke_broker
56
- end
57
- end
58
-
59
- context "with a pact directory specified" do
60
- let(:file_list) { ["spec/support/cli_test_pacts"] }
61
-
62
- it "invokes the PublishPacts command with the list of files in the directory" do
63
- expect(PactBroker::Client::PublishPacts).to receive(:call).with(
64
- anything,
65
- ["spec/support/cli_test_pacts/bar.json", "spec/support/cli_test_pacts/foo.json"],
66
- anything,
67
- anything,
68
- anything
69
- )
70
- invoke_broker
71
- end
72
- end
73
-
74
- context "with a windows directory specified" do
75
- let(:file_list) { ['spec\\support\cli_test_pacts'] }
76
-
77
- it "invokes the PublishPacts command with the list of files in the directory" do
78
- expect(PactBroker::Client::PublishPacts).to receive(:call).with(
79
- anything,
80
- ["spec/support/cli_test_pacts/bar.json", "spec/support/cli_test_pacts/foo.json"],
81
- anything,
82
- anything,
83
- anything
84
- )
85
- invoke_broker
86
- end
87
- end
88
-
89
- context "with an invalid argument specified that gets interpreted as a path" do
90
- let(:file_list) { ['--wrong'] }
91
-
92
- it "raises a more helpful error" do
93
- expect{ invoke_broker }.to raise_error(Thor::Error, 'ERROR: pact-broker publish was called with invalid arguments ["--wrong"]')
94
- end
95
- end
96
-
97
- context "when a specified file does not exist" do
98
- let(:file_list) { ['no-existy'] }
99
-
100
- it "raises a more helpful error" do
101
- expect{ invoke_broker }.to raise_error(Thor::Error, /Specified pact file 'no-existy' does not exist/)
102
- end
103
- end
104
-
105
- context "with a tag" do
106
- before do
107
- subject.options = OpenStruct.new(minimum_valid_options.merge(tag: ['foo']))
108
- end
109
-
110
- it "passes in the tag" do
111
- expect(PactBroker::Client::PublishPacts).to receive(:call).with(
112
- anything,
113
- anything,
114
- hash_including(tags: ['foo']),
115
- anything,
116
- anything
117
- )
118
- invoke_broker
119
- end
120
- end
121
-
122
- context "with tag-with-git-branch" do
123
- before do
124
- subject.options = OpenStruct.new(
125
- minimum_valid_options.merge(tag_with_git_branch: true, tag: ['foo'])
126
- )
127
- end
128
-
129
- it "determines the git branch name" do
130
- expect(PactBroker::Client::Git).to receive(:branch)
131
- invoke_broker
132
- end
133
-
134
- it "adds it to the list of tags when publishing" do
135
- expect(PactBroker::Client::PublishPacts).to receive(:call).with(
136
- anything,
137
- anything,
138
- hash_including(tags: ['foo', 'bar']),
139
- anything,
140
- anything
141
- )
142
- invoke_broker
143
- end
144
- end
145
-
146
- context "with a branch specified" do
147
- before do
148
- subject.options = OpenStruct.new(
149
- minimum_valid_options.merge(branch: "main")
150
- )
151
- end
152
-
153
- it "passes in the branch option" do
154
- expect(PactBroker::Client::PublishPacts).to receive(:call).with(
155
- anything,
156
- anything,
157
- hash_including(branch: "main"),
158
- anything,
159
- anything
160
- )
161
- invoke_broker
162
- end
163
- end
164
-
165
- context "with --auto-detect-version-properties specified" do
166
- before do
167
- subject.options = OpenStruct.new(
168
- minimum_valid_options.merge(auto_detect_version_properties: true, consumer_app_version: nil)
169
- )
170
- end
171
-
172
- it "determines the git branch name" do
173
- expect(PactBroker::Client::Git).to receive(:branch).with(raise_error: true)
174
- invoke_broker
175
- end
176
-
177
- it "passes in the auto detected branch option" do
178
- expect(PactBroker::Client::PublishPacts).to receive(:call).with(
179
- anything,
180
- anything,
181
- hash_including(branch: "bar"),
182
- anything,
183
- anything
184
- )
185
- invoke_broker
186
- end
187
-
188
- it 'determines the commit sha' do
189
- expect(PactBroker::Client::Git).to receive(:commit).with(raise_error: true)
190
- invoke_broker
191
- end
192
-
193
- it 'passes in the auto detected commit sha option' do
194
- expect(PactBroker::Client::PublishPacts).to receive(:call).with(
195
- anything,
196
- anything,
197
- hash_including(number: '6.6.6'),
198
- anything,
199
- anything
200
- )
201
- invoke_broker
202
- end
203
-
204
- it 'determines the build URL' do
205
- expect(PactBroker::Client::Git).to receive(:build_url)
206
- invoke_broker
207
- end
208
-
209
- it 'passes in the auto detected build URL' do
210
- expect(PactBroker::Client::PublishPacts).to receive(:call).with(
211
- anything,
212
- anything,
213
- hash_including(build_url: 'build_url'),
214
- anything,
215
- anything
216
- )
217
- invoke_broker
218
- end
219
-
220
- context "with the branch specified as well" do
221
- before do
222
- subject.options = OpenStruct.new(
223
- minimum_valid_options.merge(branch: "specified-branch", auto_detect_version_properties: true)
224
- )
225
- end
226
-
227
- it "uses the specified branch" do
228
- expect(PactBroker::Client::PublishPacts).to receive(:call).with(
229
- anything,
230
- anything,
231
- hash_including(branch: "specified-branch"),
232
- anything,
233
- anything
234
- )
235
- invoke_broker
236
- end
237
- end
238
- end
239
-
240
- context "with the build_url specified" do
241
- before do
242
- subject.options = OpenStruct.new(
243
- minimum_valid_options.merge(build_url: "http://ci")
244
- )
245
- end
246
-
247
- it "passes in the branch option" do
248
- expect(PactBroker::Client::PublishPacts).to receive(:call).with(
249
- anything,
250
- anything,
251
- hash_including(build_url: "http://ci"),
252
- anything,
253
- anything
254
- )
255
- invoke_broker
256
- end
257
- end
258
-
259
- context "with no consumer_app_version" do
260
- before do
261
- subject.options.consumer_app_version = nil
262
- end
263
-
264
- it "raises an error" do
265
- expect { invoke_broker }.to raise_error ::Thor::RequiredArgumentMissingError, /--consumer-app-version/
266
- end
267
- end
268
-
269
- context "with basic auth options specified" do
270
- before do
271
- subject.options = OpenStruct.new(
272
- minimum_valid_options.merge(broker_username: 'foo', broker_password: 'bar')
273
- )
274
- end
275
-
276
- it "passes in the basic auth options" do
277
- expect(PactBroker::Client::PublishPacts).to receive(:call).with(
278
- anything,
279
- anything,
280
- anything,
281
- anything,
282
- hash_including(basic_auth: { username: 'foo', password: 'bar' })
283
- )
284
- invoke_broker
285
- end
286
- end
287
-
288
- context "with basic auth and a token specified" do
289
- before do
290
- subject.options = OpenStruct.new(
291
- minimum_valid_options.merge(broker_username: 'foo', broker_password: 'bar', broker_token: 'foo')
292
- )
293
- end
294
-
295
- it "raises an error" do
296
- expect { invoke_broker }.to raise_error AuthError, /both/
297
- end
298
- end
299
-
300
- context "when no pact files are specified" do
301
- let(:file_list) { [] }
302
-
303
- it "raises an error" do
304
- expect { invoke_broker }.to raise_error ::Thor::RequiredArgumentMissingError, "No value provided for required pact_files"
305
- end
306
- end
307
-
308
- context "when an error is raised publishing" do
309
- before do
310
- allow(PactBroker::Client::PublishPacts).to receive(:call).and_raise(PactBroker::Client::Error.new('foo'))
311
- end
312
-
313
- it "raises a PactPublicationError" do
314
- expect { invoke_broker }.to raise_error PactPublicationError, /foo/
315
- end
316
- end
317
-
318
- context "when the publish command is not successful" do
319
- let(:success) { false }
320
-
321
- it "raises a SystemExit" do
322
- expect { invoke_broker }.to raise_error SystemExit
323
- end
324
- end
325
- end
326
- end
327
- end
@@ -1,287 +0,0 @@
1
- require 'pact_broker/client/cli/broker'
2
- require 'pact_broker/client/webhooks/create'
3
- require 'ostruct'
4
-
5
- module PactBroker
6
- module Client
7
- module CLI
8
- describe Broker do
9
- describe "run_webhook_commands" do
10
- before do
11
- allow($stdout).to receive(:puts)
12
- allow(PactBroker::Client::Webhooks::Create).to receive(:call).and_return(command_result)
13
- broker.options = OpenStruct.new(options_hash)
14
- end
15
-
16
- let(:broker) { Broker.new }
17
- let(:data) { 'data' }
18
- let(:user) { "username:password" }
19
- let(:command_result) { double('command result', success: success, message: 'message') }
20
- let(:success) { true }
21
- let(:header) { ["Foo: bar", "Bar: foo"] }
22
-
23
- let(:options_hash) do
24
- {
25
- uuid: '9999',
26
- description: "some webhook",
27
- request: "POST",
28
- header: header,
29
- data: data,
30
- user: user,
31
- consumer: "consumer",
32
- provider: "provider",
33
- broker_base_url: "http://broker",
34
- broker_username: "username",
35
- broker_password: "password",
36
- contract_content_changed: true,
37
- verbose: true,
38
- team_uuid: "1234"
39
- }
40
- end
41
-
42
- let(:expected_params) do
43
- {
44
- uuid: '9999',
45
- description: "some webhook",
46
- http_method: "POST",
47
- url: "http://webhook",
48
- headers: { "Foo" => "bar", "Bar" => "foo"},
49
- username: "username",
50
- password: "password",
51
- body: "data",
52
- consumer: "consumer",
53
- consumer_label: nil,
54
- provider: "provider",
55
- provider_label: nil,
56
- events: ["contract_content_changed"],
57
- team_uuid: "1234"
58
- }.tap { |it| Pact::Fixture.add_fixture(:create_webhook_params, it) }
59
- end
60
-
61
- subject { broker.run_webhook_commands "http://webhook" }
62
-
63
- it "calls PactBroker::Client::Webhooks::Create with the webhook params" do
64
- expect(PactBroker::Client::Webhooks::Create).to receive(:call) do | params, _, _ |
65
- expect(params).to eq expected_params
66
- command_result
67
- end
68
- subject
69
- end
70
-
71
- it "calls PactBroker::Client::Webhooks::Create with pact broker details" do
72
- expect(PactBroker::Client::Webhooks::Create).to receive(:call) do | _, broker_base_url, pact_broker_client_options |
73
- expect(broker_base_url).to eq "http://broker"
74
- expect(pact_broker_client_options).to eq(pact_broker_base_url: 'http://broker', basic_auth: { username: "username", password: "password"}, verbose: true)
75
- command_result
76
- end
77
- subject
78
- end
79
-
80
- context "when neither event type is selected" do
81
- before do
82
- options_hash.delete(:contract_content_changed)
83
- broker.options = OpenStruct.new(options_hash)
84
- end
85
-
86
- it "raises an error" do
87
- expect { subject }.to raise_error WebhookCreationError, /You must specify at least one/
88
- end
89
- end
90
-
91
- context "with no basic auth" do
92
- before do
93
- options_hash.delete(:broker_username)
94
- options_hash.delete(:broker_password)
95
- broker.options = OpenStruct.new(options_hash)
96
- end
97
-
98
- it "calls Webhooks::Create without basic auth" do
99
- expect(PactBroker::Client::Webhooks::Create).to receive(:call) do | _, _, pact_broker_client_options |
100
- expect(pact_broker_client_options).to eq(verbose: true, pact_broker_base_url: 'http://broker')
101
- command_result
102
- end
103
- subject
104
- end
105
- end
106
-
107
- context "with a bearer token" do
108
- before do
109
- options_hash.delete(:broker_username)
110
- options_hash.delete(:broker_password)
111
- options_hash[:broker_token] = "token"
112
- broker.options = OpenStruct.new(options_hash)
113
- end
114
-
115
- it "calls Webhooks::Create without basic auth" do
116
-
117
- expect(PactBroker::Client::Webhooks::Create).to receive(:call) do | _, _, pact_broker_client_options |
118
- expect(pact_broker_client_options).to eq(verbose: true, token: "token", pact_broker_base_url: 'http://broker')
119
- command_result
120
- end
121
- subject
122
- end
123
- end
124
-
125
- context "when there are no headers specified" do
126
- let(:header) { nil }
127
-
128
- it "calls Webhooks::Create with an empty hash of headers" do
129
- expect(PactBroker::Client::Webhooks::Create).to receive(:call) do | params, _, _ |
130
- expect(params[:headers]).to eq({})
131
- command_result
132
- end
133
- subject
134
- end
135
- end
136
-
137
- context "when data is nil" do
138
- let(:data) { nil }
139
-
140
- it "alls Webhooks::Create with a nil body" do
141
- expect(PactBroker::Client::Webhooks::Create).to receive(:call) do | params, _, _ |
142
- expect(params[:body]).to be nil
143
- command_result
144
- end
145
- subject
146
- end
147
- end
148
-
149
- context "when a uuid is provided" do
150
- before do
151
- options_hash.merge!(uuid: '9999')
152
- expected_params.merge!(uuid: '9999')
153
-
154
- broker.options = OpenStruct.new(options_hash)
155
- end
156
-
157
- it "calls PactBroker::Client::Webhooks::Create with uuid in params" do
158
- expect(PactBroker::Client::Webhooks::Create).to receive(:call) do | params, _, _ |
159
- expect(params).to eq expected_params
160
- command_result
161
- end
162
- subject
163
- end
164
- end
165
-
166
- context "when a file reference is passed for the data" do
167
- before do
168
- FileUtils.mkdir_p "tmp"
169
- File.open("tmp/body.json", "w") { |file| file << "file" }
170
- end
171
-
172
- let(:data) { "@tmp/body.json" }
173
-
174
- it "reads the file and passes it in to the Webhooks::Create call" do
175
- expect(PactBroker::Client::Webhooks::Create).to receive(:call) do | params, _, _ |
176
- expect(params[:body]).to eq "file"
177
- command_result
178
- end
179
- subject
180
- end
181
-
182
- context "when the file is not found" do
183
-
184
- let(:data) { "@doesnotexist.json" }
185
-
186
- it "raises a WebhookCreationError" do
187
- expect { subject }.to raise_error WebhookCreationError, /Couldn't read data from file/
188
- end
189
- end
190
-
191
- context "when successful" do
192
- it "prints the message to stdout" do
193
- expect($stdout).to receive(:puts).with('message')
194
- subject
195
- end
196
- end
197
-
198
- context "when not successful" do
199
- let(:success) { false }
200
-
201
- it "prints the message to stderr" do
202
- expect($stdout).to receive(:puts).with('message')
203
- begin
204
- subject
205
- rescue SystemExit
206
- end
207
- end
208
-
209
- it "exits with code 1" do
210
- exited_with_error = false
211
- begin
212
- subject
213
- rescue SystemExit
214
- exited_with_error = true
215
- end
216
- expect(exited_with_error).to be true
217
- end
218
- end
219
-
220
- context "when a PactBroker::Client::Error is raised" do
221
- before do
222
- allow(PactBroker::Client::Webhooks::Create).to receive(:call).and_raise(PactBroker::Client::Error, "foo")
223
- end
224
-
225
- it "raises a WebhookCreationError which does not show an ugly stack trace" do
226
- expect { subject }.to raise_error(WebhookCreationError, /foo/)
227
- end
228
- end
229
-
230
- end
231
-
232
- context "when both consumer name and label options are specified" do
233
- before do
234
- options_hash[:consumer_label] = "consumer_label"
235
- broker.options = OpenStruct.new(options_hash)
236
- end
237
-
238
- it "raises a WebhookCreationError" do
239
- expect { subject }.to raise_error(
240
- WebhookCreationError,
241
- "Consumer name (--consumer) and label (--consumer_label) options are mutually exclusive"
242
- )
243
- end
244
- end
245
-
246
- context "when both provider name and label options are specified" do
247
- before do
248
- options_hash[:provider_label] = "provider_label"
249
- broker.options = OpenStruct.new(options_hash)
250
- end
251
-
252
- it "raises a WebhookCreationError" do
253
- expect { subject }.to raise_error(
254
- WebhookCreationError,
255
- "Provider name (--provider) and label (--provider_label) options are mutually exclusive"
256
- )
257
- end
258
- end
259
-
260
- context "when participant labels are specified" do
261
- before do
262
- options_hash.delete(:consumer)
263
- options_hash.delete(:provider)
264
- options_hash.merge!(consumer_label: 'consumer_label', provider_label: 'provider_label')
265
- expected_params.merge!(
266
- consumer: nil,
267
- consumer_label: 'consumer_label',
268
- provider: nil,
269
- provider_label: 'provider_label'
270
- )
271
-
272
- broker.options = OpenStruct.new(options_hash)
273
- end
274
-
275
- it "calls PactBroker::Client::Webhooks::Create with participant labels in params" do
276
- expect(PactBroker::Client::Webhooks::Create).to receive(:call) do | params, _, _ |
277
- expect(params).to eq expected_params
278
- command_result
279
- end
280
- subject
281
- end
282
- end
283
- end
284
- end
285
- end
286
- end
287
- end