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,238 +0,0 @@
1
- require 'pact_broker/client/hal/http_client'
2
- require "faraday"
3
- require "faraday/retry"
4
-
5
- module PactBroker::Client
6
- module Hal
7
- describe HttpClient do
8
- subject { HttpClient.new(username: 'foo', password: 'bar') }
9
-
10
- describe "get" do
11
- before do
12
- allow(subject).to receive(:until_truthy_or_max_times) { |&block| block.call }
13
- end
14
-
15
- let!(:request) do
16
- stub_request(:get, "http://example.org/").
17
- with( headers: {
18
- 'Accept'=>'application/hal+json',
19
- 'Authorization'=>'Basic Zm9vOmJhcg=='
20
- }).
21
- to_return(status: 200, body: response_body, headers: {'Content-Type' => 'application/json'})
22
- end
23
-
24
- let(:response_body) { {some: 'json'}.to_json }
25
- let(:do_get) { subject.get('http://example.org') }
26
-
27
- it "performs a get request" do
28
- do_get
29
- expect(request).to have_been_made
30
- end
31
-
32
- context "with get params" do
33
- let!(:request) do
34
- stub_request(:get, "http://example.org/?foo=hello+world&bar=wiffle").
35
- to_return(status: 200)
36
- end
37
-
38
- let(:do_get) { subject.get('http://example.org', { 'foo' => 'hello world', 'bar' => 'wiffle' }) }
39
-
40
- it "correctly converts and encodes get params" do
41
- do_get
42
- expect(request).to have_been_made
43
- end
44
- end
45
-
46
- it "retries on failure" do
47
- expect(subject).to receive(:until_truthy_or_max_times)
48
- do_get
49
- end
50
-
51
- it "returns a response" do
52
- expect(do_get.body).to eq({"some" => "json"})
53
- end
54
-
55
- end
56
-
57
- describe "post" do
58
- before do
59
- allow(subject).to receive(:until_truthy_or_max_times) { |&block| block.call }
60
- end
61
-
62
- let!(:request) do
63
- stub_request(:post, "http://example.org/").
64
- with( headers: {
65
- 'Accept'=>'application/hal+json',
66
- 'Authorization'=>'Basic Zm9vOmJhcg==',
67
- 'Content-Type'=>'application/json'
68
- },
69
- body: request_body).
70
- to_return(status: 200, body: response_body, headers: {'Content-Type' => 'application/json'})
71
- end
72
-
73
- let(:request_body) { {some: 'data'}.to_json }
74
- let(:response_body) { {some: 'json'}.to_json }
75
-
76
- let(:do_post) { subject.post('http://example.org/', request_body) }
77
-
78
- it "performs a post request" do
79
- do_post
80
- expect(request).to have_been_made
81
- end
82
-
83
- it "calls Retry.until_truthy_or_max_times" do
84
- expect(subject).to receive(:until_truthy_or_max_times)
85
- do_post
86
- end
87
-
88
- it "returns a response" do
89
- expect(do_post.body).to eq({"some" => "json"})
90
- end
91
-
92
- context "with custom headers" do
93
- let!(:request) do
94
- stub_request(:post, "http://example.org/").
95
- with( headers: {
96
- 'Accept'=>'foo'
97
- }).
98
- to_return(status: 200)
99
- end
100
-
101
- let(:do_post) { subject.post('http://example.org/', request_body, {"Accept" => "foo"} ) }
102
-
103
- it "performs a post request with custom headers" do
104
- do_post
105
- expect(request).to have_been_made
106
- end
107
- end
108
- end
109
-
110
- describe "integration test" do
111
- before do
112
- allow(subject).to receive(:sleep)
113
- end
114
-
115
- let(:do_get) { subject.get('http://example.org') }
116
-
117
- context "with a 50x error is returned less than the max number of tries" do
118
- let!(:request) do
119
- stub_request(:get, "http://example.org").
120
- to_return({ status: 500 }, { status: 502 }, { status: 503 }, { status: 200 })
121
- end
122
-
123
- it "retries" do
124
- expect(do_get.status).to eq 200
125
- end
126
- end
127
-
128
- context "with a 50x error is returned more than the max number of tries" do
129
- let!(:request) do
130
- stub_request(:get, "http://example.org").
131
- to_return({ status: 500 }, { status: 501 }, { status: 502 }, { status: 503 }, { status: 504 })
132
- end
133
-
134
- it "retries and returns the last 50x response" do
135
- expect(do_get.status).to eq 504
136
- end
137
- end
138
-
139
- context "when exceptions are raised" do
140
- before do
141
- allow($stderr).to receive(:puts)
142
- end
143
-
144
- let!(:request) do
145
- stub_request(:get, "http://example.org")
146
- .to_raise(Errno::ECONNREFUSED)
147
- end
148
-
149
- it "logs the error" do
150
- expect($stderr).to receive(:puts).with(/Errno::ECONNREFUSED/)
151
- begin
152
- do_get
153
- rescue Errno::ECONNREFUSED
154
- end
155
- end
156
-
157
- it "retries and raises the last exception" do
158
- expect { do_get }.to raise_error(Errno::ECONNREFUSED)
159
- end
160
- end
161
- end
162
-
163
- describe "x509 certificate" do
164
- FAKE_SERVER_URL = 'https://localhost:4444'
165
- X509_CERT_FILE_PATH = './spec/fixtures/certificates/client_cert.pem'
166
- X509_KEY_FILE_PATH = './spec/fixtures/certificates/key.pem'
167
- UNSIGNED_X509_CERT_FILE_PATH = './spec/fixtures/certificates/unsigned_cert.pem'
168
- UNSIGNED_X509_KEY_FILE_PATH = './spec/fixtures/certificates/unsigned_key.pem'
169
-
170
- def wait_for_server_to_start
171
- Faraday.new(
172
- url: FAKE_SERVER_URL,
173
- ssl: {
174
- verify: false,
175
- client_cert: OpenSSL::X509::Certificate.new(File.read(X509_CERT_FILE_PATH)),
176
- client_key: OpenSSL::PKey::RSA.new(File.read(X509_KEY_FILE_PATH))
177
- }
178
- ) do |builder|
179
- builder.request :retry, max: 20, interval: 0.5, exceptions: [StandardError]
180
- builder.adapter :net_http
181
- end.get
182
- end
183
-
184
- let(:do_get) { subject.get(FAKE_SERVER_URL) }
185
-
186
- before(:all) do
187
- @pipe = IO.popen("bundle exec ruby ./spec/support/ssl_server.rb")
188
- ENV['SSL_CERT_FILE'] = "./spec/fixtures/certificates/ca_cert.pem"
189
-
190
- wait_for_server_to_start()
191
- end
192
-
193
- context "with valid x509 client certificates" do
194
- before do
195
- ENV['X509_CLIENT_CERT_FILE'] = X509_CERT_FILE_PATH
196
- ENV['X509_CLIENT_KEY_FILE'] = X509_KEY_FILE_PATH
197
- end
198
-
199
- it "succeeds" do
200
- expect(do_get.status).to eq 200
201
- end
202
- end
203
-
204
- context "when invalid x509 certificates are set" do
205
- before do
206
- ENV['X509_CLIENT_CERT_FILE'] = UNSIGNED_X509_CERT_FILE_PATH
207
- ENV['X509_CLIENT_KEY_FILE'] = UNSIGNED_X509_KEY_FILE_PATH
208
- end
209
-
210
- it "fails raising SSL error" do
211
- expect { do_get }
212
- .to raise_error { |error|
213
- expect([OpenSSL::SSL::SSLError, Errno::ECONNRESET]).to include(error.class)
214
- }
215
- end
216
- end
217
-
218
- context "when no x509 certificates are set" do
219
- before do
220
- ENV['X509_CLIENT_CERT_FILE'] = nil
221
- ENV['X509_CLIENT_KEY_FILE'] = nil
222
- end
223
-
224
- it "fails raising SSL error" do
225
- expect { do_get }
226
- .to raise_error { |error|
227
- expect([OpenSSL::SSL::SSLError, Errno::ECONNRESET]).to include(error.class)
228
- }
229
- end
230
- end
231
-
232
- after(:all) do
233
- Process.kill "KILL", @pipe.pid
234
- end
235
- end
236
- end
237
- end
238
- end
@@ -1,127 +0,0 @@
1
- require 'pact_broker/client/hal/link'
2
- require 'pact_broker/client/hal/entity'
3
- require 'pact_broker/client/hal/http_client'
4
-
5
- module PactBroker::Client
6
- module Hal
7
- describe Link do
8
- before do
9
- allow(response).to receive(:header).with("Content-Type").and_return(content_type)
10
- end
11
-
12
- let(:http_client) do
13
- instance_double('PactBroker::Client::Hal::HttpClient', post: response)
14
- end
15
-
16
- let(:response) do
17
- instance_double('PactBroker::Client::Hal::HttpClient::Response', success?: success, body: response_body, raw_body: response_body.to_json)
18
- end
19
-
20
- let(:success) { true }
21
-
22
- let(:entity) do
23
- instance_double('PactBroker::Client::Hal::Entity')
24
- end
25
-
26
- let(:attrs) do
27
- {
28
- 'href' => 'http://foo/{bar}',
29
- 'title' => 'title',
30
- method: :post
31
- }
32
- end
33
-
34
- let(:response_body) do
35
- {
36
- 'some' => 'body'
37
- }
38
- end
39
-
40
- let(:content_type) { nil }
41
-
42
- subject { Link.new(attrs, http_client) }
43
-
44
- before do
45
- allow(PactBroker::Client::Hal::Entity).to receive(:new).and_return(entity)
46
- end
47
-
48
- describe "#run" do
49
- let(:do_run) { subject.run('foo' => 'bar') }
50
-
51
- it "executes the configured http request" do
52
- expect(http_client).to receive(:post)
53
- do_run
54
- end
55
-
56
- it "creates an Entity" do
57
- expect(PactBroker::Client::Hal::Entity).to receive(:new).with("http://foo/{bar}", response_body, http_client, response)
58
- do_run
59
- end
60
-
61
- it "returns an Entity" do
62
- expect(do_run).to eq entity
63
- end
64
-
65
- context "when an error response is returned" do
66
- before do
67
- allow(PactBroker::Client::Hal::ErrorEntity).to receive(:new).and_return(entity)
68
- end
69
-
70
- let(:success) { false }
71
-
72
- it "creates an ErrorEntity" do
73
- expect(PactBroker::Client::Hal::ErrorEntity).to receive(:new).with("http://foo/{bar}", response_body.to_json, http_client, response)
74
- do_run
75
- end
76
-
77
- context "when a JSON error is returned" do
78
- let(:content_type) { "application/json" }
79
-
80
- it "parses the response body" do
81
- expect(PactBroker::Client::Hal::ErrorEntity).to receive(:new).with("http://foo/{bar}", response_body, http_client, response)
82
- do_run
83
- end
84
- end
85
- end
86
- end
87
-
88
- describe "#get" do
89
- before do
90
- allow(http_client).to receive(:get).and_return(response)
91
- end
92
-
93
- let(:do_get) { subject.get({ 'foo' => 'bar' }) }
94
-
95
- it "executes an HTTP Get request" do
96
- expect(http_client).to receive(:get).with('http://foo/{bar}', { 'foo' => 'bar' }, {})
97
- do_get
98
- end
99
- end
100
-
101
- describe "#post" do
102
- let(:do_post) { subject.post({ 'foo' => 'bar' }, { 'Accept' => 'foo' }) }
103
-
104
- context "with custom headers" do
105
- it "executes an HTTP Post request with the custom headers" do
106
- expect(http_client).to receive(:post).with('http://foo/{bar}', '{"foo":"bar"}', { 'Accept' => 'foo' })
107
- do_post
108
- end
109
- end
110
- end
111
-
112
- describe "#expand" do
113
- it "returns a duplicate Link with the expanded href" do
114
- expect(subject.expand(bar: 'wiffle').href).to eq "http://foo/wiffle"
115
- end
116
-
117
- it "returns a duplicate Link with the expanded href with URL escaping" do
118
- expect(subject.expand(bar: 'wiffle meep').href).to eq "http://foo/wiffle%20meep"
119
- end
120
-
121
- it "returns a duplicate Link with the expanded href with URL escaping for forward slashes" do
122
- expect(subject.expand(bar: 'wiffle/meep').href).to eq "http://foo/wiffle%2Fmeep"
123
- end
124
- end
125
- end
126
- end
127
- end
@@ -1,42 +0,0 @@
1
-
2
- require 'pact_broker/client/matrix/abbreviate_version_number'
3
-
4
- module PactBroker
5
- module Client
6
- describe Matrix::AbbreviateVersionNumber do
7
- describe '.call' do
8
- subject(:result) { described_class.call(version) }
9
-
10
- context 'when version is nil' do
11
- let(:version) { nil }
12
- it { is_expected.to be_nil }
13
- end
14
-
15
- context 'when version is git sha' do
16
- let(:version) { '182f9c6e4d7a5779c4507cb8b3e505ac927d0394' }
17
- it { is_expected.to eq('182f9c6...') }
18
- end
19
-
20
- context 'when version is too long' do
21
- let(:version) { '182f9c6e4d7a5779c4507cb8b3e505ac927d0394' * 2 }
22
- it { is_expected.to eq(version[0...60] + '...') }
23
- end
24
-
25
- context 'when the version is something unknown and fits max length' do
26
- let(:version) { '123' }
27
- it { is_expected.to eq('123') }
28
- end
29
-
30
- context 'when version is embedded into semantic version v1' do
31
- let(:version) { 'v1.3.4+182f9c6e4d7a5779c4507cb8b3e505ac927d0394' }
32
- it { is_expected.to eq('v1.3.4+182f9c6...') }
33
- end
34
-
35
- context 'when version is embedded into semantic version v2' do
36
- let(:version) { '1.3.4(182f9c6e4d7a5779c4507cb8b3e505ac927d0394)' }
37
- it { is_expected.to eq('1.3.4(182f9c6...)') }
38
- end
39
- end
40
- end
41
- end
42
- end
@@ -1,70 +0,0 @@
1
- require 'pact_broker/client/matrix/resource'
2
-
3
- module PactBroker
4
- module Client
5
- class Matrix
6
- describe Resource do
7
-
8
- let(:matrix_hash) { JSON.parse(File.read('spec/support/matrix.json'), symbolize_names: true) }
9
-
10
- subject { Resource.new(matrix_hash) }
11
-
12
- describe "any_unknown?" do
13
- context "when $summary.unknown is greater than 0" do
14
- it "is true" do
15
- expect(subject.any_unknown?).to be true
16
- end
17
- end
18
-
19
- context "when $summary.unknown is 0" do
20
- before do
21
- matrix_hash[:summary][:unknown] = 0
22
- end
23
-
24
- it "is false" do
25
- expect(subject.any_unknown?).to be false
26
- end
27
- end
28
- end
29
-
30
- describe "supports_unknown_count?" do
31
- context "when $summary.unknown is present" do
32
- it "is true" do
33
- expect(subject.supports_unknown_count?).to be true
34
- end
35
- end
36
-
37
- context "when $summary.unknown is nil" do
38
- before do
39
- matrix_hash[:summary][:unknown] = nil
40
- end
41
-
42
- it "is false" do
43
- expect(subject.supports_unknown_count?).to be false
44
- end
45
- end
46
-
47
- context "when $summary.unknown is not an Integer" do
48
- before do
49
- matrix_hash[:summary][:unknown] = true
50
- end
51
-
52
- it "is false" do
53
- expect(subject.supports_unknown_count?).to be false
54
- end
55
- end
56
-
57
- context "when $summary.unknown is not present" do
58
- before do
59
- matrix_hash[:summary].delete(:unknown)
60
- end
61
-
62
- it "is false" do
63
- expect(subject.supports_unknown_count?).to be false
64
- end
65
- end
66
- end
67
- end
68
- end
69
- end
70
- end
@@ -1,63 +0,0 @@
1
- require 'pact_broker/client/matrix/resource'
2
- require 'pact_broker/client/matrix/text_formatter'
3
-
4
- module PactBroker
5
- module Client
6
- describe Matrix::TextFormatter do
7
- let(:matrix) { PactBroker::Client::Matrix::Resource.new(JSON.parse(File.read('spec/support/matrix.json'), symbolize_names: true)) }
8
- let(:expected_matrix_lines) { File.read('spec/support/matrix.txt') }
9
-
10
- # SublimeText removes whitespace from the end of files when you save them,
11
- # so removing trailing whitespace before comparing
12
- def strip_trailing_whitespace(text)
13
- text.split("\n").collect(&:strip).join("\n")
14
- end
15
-
16
- subject { strip_trailing_whitespace(Matrix::TextFormatter.call(matrix)) }
17
-
18
- context "with valid data" do
19
- it "it has the right text" do
20
- expect(subject).to start_with expected_matrix_lines
21
- end
22
- end
23
-
24
- context "with invalid data" do
25
- let(:expected_matrix_lines) { File.read('spec/support/matrix_error.txt') }
26
- let(:matrix) { PactBroker::Client::Matrix::Resource.new(matrix: [{}]) }
27
-
28
- it "doesn't blow up" do
29
- expect(subject).to eq expected_matrix_lines
30
- end
31
- end
32
-
33
- context "when some rows have a verification result URL and some don't" do
34
- let(:matrix_lines) do
35
- line_creator = -> { JSON.parse(File.read('spec/support/matrix.json'), symbolize_names: true)[:matrix].first }
36
- line_1 = line_creator.call
37
- line_2 = line_creator.call
38
- line_3 = line_creator.call
39
-
40
- # ensure the data is as expected
41
- expect(line_1.dig(:consumer, :version, :number)).to_not be nil
42
- expect(line_1.dig(:provider, :version, :number)).to_not be nil
43
-
44
- line_1[:consumer][:version][:number] = "4"
45
- line_2[:consumer][:version][:number] = "3"
46
- line_3[:consumer][:version][:number] = "5"
47
-
48
- line_2[:verificationResult] = nil
49
- line_3[:verificationResult][:success] = false
50
- [line_1, line_2, line_3].shuffle
51
- end
52
-
53
- let(:matrix) { PactBroker::Client::Matrix::Resource.new(matrix: matrix_lines) }
54
-
55
- let(:expected_matrix_lines) { File.read('spec/support/matrix_with_results.txt') }
56
-
57
- it "only provides a result number for the lines that have a result URL" do
58
- expect(subject).to eq expected_matrix_lines
59
- end
60
- end
61
- end
62
- end
63
- end
@@ -1,17 +0,0 @@
1
- require 'pact_broker/client/matrix'
2
-
3
- module PactBroker
4
- module Client
5
- describe Matrix do
6
- let(:matrix) { Matrix.new(base_url: 'http://example.org') }
7
-
8
- context "when the matrix resource is not found because the broker is the wrong version" do
9
- let!(:request) { stub_request(:get, /matrix/).to_return(status: 404) }
10
-
11
- it "raises a helpful error" do
12
- expect { matrix.get([{name: "Foo", version: "1"}]) }.to raise_error PactBroker::Client::Error, %r{Matrix resource not found at http://example.org/matrix}
13
- end
14
- end
15
- end
16
- end
17
- end