pact_broker-client 1.75.3 → 1.75.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/lib/pact_broker/client/version.rb +1 -1
- metadata +5 -216
- data/.github/workflows/test.yml +0 -59
- data/.rspec +0 -3
- data/lib/pact_broker/client/pacts/list_latest_versions.rb +0 -66
- data/lib/pact_broker/client/webhooks/test.rb +0 -16
- data/pact-broker-client.gemspec +0 -31
- data/spec/fixtures/MyConsumer-MyProvider (1).json +0 -37
- data/spec/fixtures/MyConsumer-MyProvider.json +0 -37
- data/spec/fixtures/approvals/can_i_deploy_failure_dry_run.approved.txt +0 -7
- data/spec/fixtures/approvals/can_i_deploy_ignore.approved.txt +0 -13
- data/spec/fixtures/approvals/can_i_deploy_success_dry_run.approved.txt +0 -7
- data/spec/fixtures/approvals/describe_environment.approved.txt +0 -7
- data/spec/fixtures/approvals/describe_pacticipant.approved.txt +0 -2
- data/spec/fixtures/approvals/list_environments.approved.txt +0 -3
- data/spec/fixtures/approvals/publish_provider_contract.approved.txt +0 -2
- data/spec/fixtures/certificates/ca_cert.pem +0 -19
- data/spec/fixtures/certificates/ca_cert.srl +0 -1
- data/spec/fixtures/certificates/ca_key.pem +0 -28
- data/spec/fixtures/certificates/client_cert.pem +0 -17
- data/spec/fixtures/certificates/key.pem +0 -28
- data/spec/fixtures/certificates/server.csr +0 -15
- data/spec/fixtures/certificates/unsigned_cert.pem +0 -19
- data/spec/fixtures/certificates/unsigned_key.pem +0 -28
- data/spec/fixtures/foo-bar.json +0 -31
- data/spec/integration/can_i_deploy_spec.rb +0 -24
- data/spec/integration/can_i_merge_spec.rb +0 -44
- data/spec/integration/create_version_tag_spec.rb +0 -20
- data/spec/integration/describe_environment_spec.rb +0 -31
- data/spec/integration/publish_provider_contract_spec.rb +0 -53
- data/spec/integration/unknown_options_spec.rb +0 -39
- data/spec/lib/pact_broker/client/base_client_spec.rb +0 -182
- data/spec/lib/pact_broker/client/branches/delete_branch_spec.rb +0 -103
- data/spec/lib/pact_broker/client/can_i_deploy_spec.rb +0 -250
- data/spec/lib/pact_broker/client/cli/broker_can_i_deploy_spec.rb +0 -196
- data/spec/lib/pact_broker/client/cli/broker_create_or_update_webhook_spec.rb +0 -23
- data/spec/lib/pact_broker/client/cli/broker_create_webhook_spec.rb +0 -23
- data/spec/lib/pact_broker/client/cli/broker_publish_spec.rb +0 -327
- data/spec/lib/pact_broker/client/cli/broker_run_webhook_commands_spec.rb +0 -287
- data/spec/lib/pact_broker/client/cli/custom_thor_spec.rb +0 -174
- data/spec/lib/pact_broker/client/cli/version_selector_options_parser_spec.rb +0 -97
- data/spec/lib/pact_broker/client/deployments/record_deployment_spec.rb +0 -224
- data/spec/lib/pact_broker/client/deployments/record_support_ended_spec.rb +0 -208
- data/spec/lib/pact_broker/client/deployments/record_undeployment_spec.rb +0 -227
- data/spec/lib/pact_broker/client/environments/delete_environment_spec.rb +0 -120
- data/spec/lib/pact_broker/client/environments/describe_environment_spec.rb +0 -89
- data/spec/lib/pact_broker/client/environments/update_environment_spec.rb +0 -167
- data/spec/lib/pact_broker/client/generate_display_name_spec.rb +0 -39
- data/spec/lib/pact_broker/client/git_spec.rb +0 -159
- data/spec/lib/pact_broker/client/hal/authorization_header_redactor_spec.rb +0 -17
- data/spec/lib/pact_broker/client/hal/entity_spec.rb +0 -149
- data/spec/lib/pact_broker/client/hal/http_client_spec.rb +0 -238
- data/spec/lib/pact_broker/client/hal/link_spec.rb +0 -127
- data/spec/lib/pact_broker/client/matrix/abbreviate_version_number_spec.rb +0 -42
- data/spec/lib/pact_broker/client/matrix/resource_spec.rb +0 -70
- data/spec/lib/pact_broker/client/matrix/text_formatter_spec.rb +0 -63
- data/spec/lib/pact_broker/client/matrix_spec.rb +0 -17
- data/spec/lib/pact_broker/client/merge_pacts_spec.rb +0 -198
- data/spec/lib/pact_broker/client/pact_broker_client_spec.rb +0 -47
- data/spec/lib/pact_broker/client/pacticipants/create_spec.rb +0 -31
- data/spec/lib/pact_broker/client/pacticipants_spec.rb +0 -18
- data/spec/lib/pact_broker/client/publish_pacts_the_old_way_spec.rb +0 -272
- data/spec/lib/pact_broker/client/retry_spec.rb +0 -119
- data/spec/lib/pact_broker/client/tasks/publication_task_spec.rb +0 -231
- data/spec/lib/pact_broker/client/versions/create_spec.rb +0 -174
- data/spec/lib/pact_broker/client/versions/describe_spec.rb +0 -64
- data/spec/lib/pact_broker/client/versions_spec.rb +0 -34
- data/spec/lib/pact_broker/client/webhooks/create_spec.rb +0 -99
- data/spec/lib/pactflow/client/provider_contracts/publish_spec.rb +0 -179
- data/spec/pacts/pact_broker_client-pact_broker.json +0 -2969
- data/spec/pacts/pact_broker_client-pactflow.json +0 -288
- data/spec/readme_spec.rb +0 -16
- data/spec/service_providers/create_environment_spec.rb +0 -78
- data/spec/service_providers/delete_branch_spec.rb +0 -68
- data/spec/service_providers/extra_goodies_spec.rb +0 -108
- data/spec/service_providers/list_environments_spec.rb +0 -77
- data/spec/service_providers/list_latest_pact_versions_spec.rb.bak +0 -44
- data/spec/service_providers/pact_broker_client_matrix_ignore_spec.rb +0 -98
- data/spec/service_providers/pact_broker_client_matrix_spec.rb +0 -292
- data/spec/service_providers/pact_broker_client_pacticipant_version_spec.rb +0 -56
- data/spec/service_providers/pact_broker_client_publish_spec.rb +0 -135
- data/spec/service_providers/pact_broker_client_register_repository_spec.rb +0 -49
- data/spec/service_providers/pact_broker_client_retrieve_all_pacts_for_provider_spec.rb +0 -53
- data/spec/service_providers/pact_broker_client_retrieve_pact_spec.rb +0 -109
- data/spec/service_providers/pact_broker_client_tags_spec.rb +0 -101
- data/spec/service_providers/pact_broker_client_versions_spec.rb +0 -113
- data/spec/service_providers/pact_helper.rb +0 -136
- data/spec/service_providers/pactflow_publish_provider_contract_spec.rb +0 -137
- data/spec/service_providers/pactflow_publish_provider_contract_the_old_way_spec.rb +0 -129
- data/spec/service_providers/pactflow_webhooks_create_spec.rb +0 -86
- data/spec/service_providers/pacticipants_create_spec.rb +0 -119
- data/spec/service_providers/publish_pacts_spec.rb +0 -114
- data/spec/service_providers/record_deployment_spec.rb +0 -199
- data/spec/service_providers/record_release_spec.rb +0 -130
- data/spec/service_providers/record_undeployment_spec.rb +0 -164
- data/spec/service_providers/webhooks_create_spec.rb +0 -391
- data/spec/spec_helper.rb +0 -68
- data/spec/support/approvals.rb +0 -26
- data/spec/support/cli_test_pacts/bar.json +0 -0
- data/spec/support/cli_test_pacts/foo.json +0 -0
- data/spec/support/latest_pacts_for_provider.json +0 -15
- data/spec/support/matrix.json +0 -35
- data/spec/support/matrix.txt +0 -3
- data/spec/support/matrix_error.txt +0 -3
- data/spec/support/matrix_with_results.txt +0 -10
- data/spec/support/pacticipant_get.json +0 -18
- data/spec/support/pacticipants_list.json +0 -26
- data/spec/support/pacts_latest_list.json +0 -41
- data/spec/support/shared_context.rb +0 -25
- data/spec/support/ssl_server.rb +0 -42
@@ -1,198 +0,0 @@
|
|
1
|
-
require 'pact_broker/client/merge_pacts'
|
2
|
-
|
3
|
-
module PactBroker
|
4
|
-
module Client
|
5
|
-
describe MergePacts do
|
6
|
-
describe ".call" do
|
7
|
-
describe "with a pact with interactions" do
|
8
|
-
let(:pact_hash_1) do
|
9
|
-
{
|
10
|
-
other: 'info',
|
11
|
-
interactions: [
|
12
|
-
{ providerState: 1, description: 1, foo: 'bar' }
|
13
|
-
]
|
14
|
-
}
|
15
|
-
end
|
16
|
-
|
17
|
-
let(:pact_hash_2) do
|
18
|
-
{
|
19
|
-
interactions: [
|
20
|
-
{ providerState: 2, description: 2, foo: 'wiffle' }
|
21
|
-
]
|
22
|
-
}
|
23
|
-
end
|
24
|
-
|
25
|
-
let(:pact_hash_3) do
|
26
|
-
{
|
27
|
-
interactions: [
|
28
|
-
{ providerState: 3, description: 3, foo: 'meep' },
|
29
|
-
{ providerState: 1, description: 1, foo: 'bar' }
|
30
|
-
]
|
31
|
-
}
|
32
|
-
end
|
33
|
-
|
34
|
-
let(:pact_hashes) { [pact_hash_1, pact_hash_2, pact_hash_3] }
|
35
|
-
|
36
|
-
let(:expected_merge) do
|
37
|
-
{
|
38
|
-
other: 'info',
|
39
|
-
interactions: [
|
40
|
-
{ providerState: 1, description: 1, foo: 'bar' },
|
41
|
-
{ providerState: 2, description: 2, foo: 'wiffle' },
|
42
|
-
{ providerState: 3, description: 3, foo: 'meep' }
|
43
|
-
]
|
44
|
-
}
|
45
|
-
end
|
46
|
-
|
47
|
-
subject { MergePacts.call(pact_hashes) }
|
48
|
-
|
49
|
-
it "merges the interactions by consumer/provider" do
|
50
|
-
expect(subject).to eq expected_merge
|
51
|
-
end
|
52
|
-
|
53
|
-
context "when an interaction is found with the same state and description but has a difference elsewhere" do
|
54
|
-
let(:pact_hash_3) do
|
55
|
-
{
|
56
|
-
interactions: [
|
57
|
-
{ providerState: 3, description: 3, foo: 'meep' },
|
58
|
-
{ providerState: 1, description: 1, foo: 'different' }
|
59
|
-
]
|
60
|
-
}
|
61
|
-
end
|
62
|
-
|
63
|
-
it "raises an error" do
|
64
|
-
expect { subject }.to raise_error PactMergeError, /foo.*different/
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
describe "with a pact with messages" do
|
70
|
-
let(:pact_hash_1) do
|
71
|
-
{
|
72
|
-
other: 'info',
|
73
|
-
messages: [
|
74
|
-
{ providerState: 1, description: 1, foo: 'bar' }
|
75
|
-
]
|
76
|
-
}
|
77
|
-
end
|
78
|
-
|
79
|
-
let(:pact_hash_2) do
|
80
|
-
{
|
81
|
-
messages: [
|
82
|
-
{ providerState: 2, description: 2, foo: 'wiffle' }
|
83
|
-
]
|
84
|
-
}
|
85
|
-
end
|
86
|
-
|
87
|
-
let(:pact_hash_3) do
|
88
|
-
{
|
89
|
-
messages: [
|
90
|
-
{ providerState: 3, description: 3, foo: 'meep' },
|
91
|
-
{ providerState: 1, description: 1, foo: 'bar' }
|
92
|
-
]
|
93
|
-
}
|
94
|
-
end
|
95
|
-
|
96
|
-
let(:pact_hashes) { [pact_hash_1, pact_hash_2, pact_hash_3] }
|
97
|
-
|
98
|
-
let(:expected_merge) do
|
99
|
-
{
|
100
|
-
other: 'info',
|
101
|
-
messages: [
|
102
|
-
{ providerState: 1, description: 1, foo: 'bar' },
|
103
|
-
{ providerState: 2, description: 2, foo: 'wiffle' },
|
104
|
-
{ providerState: 3, description: 3, foo: 'meep' }
|
105
|
-
]
|
106
|
-
}
|
107
|
-
end
|
108
|
-
|
109
|
-
subject { MergePacts.call(pact_hashes) }
|
110
|
-
|
111
|
-
it "merges the messages by consumer/provider" do
|
112
|
-
expect(subject).to eq expected_merge
|
113
|
-
end
|
114
|
-
|
115
|
-
context "when an interaction is found with the same state and description but has a difference elsewhere" do
|
116
|
-
let(:pact_hash_3) do
|
117
|
-
{
|
118
|
-
messages: [
|
119
|
-
{ providerState: 3, description: 3, foo: 'meep' },
|
120
|
-
{ providerState: 1, description: 1, foo: 'different' }
|
121
|
-
]
|
122
|
-
}
|
123
|
-
end
|
124
|
-
|
125
|
-
it "raises an error" do
|
126
|
-
expect { subject }.to raise_error PactMergeError, /foo.*different/
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
describe "with a pact with messages and a pact with interactions" do
|
132
|
-
let(:pact_hash_1) do
|
133
|
-
{
|
134
|
-
other: 'info',
|
135
|
-
messages: [
|
136
|
-
{ providerState: 1, description: 1, foo: 'bar' }
|
137
|
-
]
|
138
|
-
}
|
139
|
-
end
|
140
|
-
|
141
|
-
let(:pact_hash_2) do
|
142
|
-
{
|
143
|
-
interactions: [
|
144
|
-
{ providerState: 2, description: 2, foo: 'wiffle' }
|
145
|
-
]
|
146
|
-
}
|
147
|
-
end
|
148
|
-
|
149
|
-
let(:pact_hashes) { [pact_hash_1, pact_hash_2] }
|
150
|
-
|
151
|
-
let(:expected_merge) do
|
152
|
-
{
|
153
|
-
other: 'info',
|
154
|
-
messages: [
|
155
|
-
{ providerState: 1, description: 1, foo: 'bar' }
|
156
|
-
],
|
157
|
-
interactions: [
|
158
|
-
{ providerState: 2, description: 2, foo: 'wiffle' }
|
159
|
-
]
|
160
|
-
}
|
161
|
-
end
|
162
|
-
|
163
|
-
subject { MergePacts.call(pact_hashes) }
|
164
|
-
|
165
|
-
it "merges the messages by consumer/provider" do
|
166
|
-
expect(subject).to eq expected_merge
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
describe "with v3 pacts" do
|
171
|
-
let(:pact_hash_1) { JSON.parse(File.read("spec/fixtures/MyConsumer-MyProvider.json"), symbolize_names: true) }
|
172
|
-
let(:pact_hash_2) { JSON.parse(File.read("spec/fixtures/MyConsumer-MyProvider (1).json"), symbolize_names: true) }
|
173
|
-
let(:pact_hashes) { [pact_hash_1, pact_hash_2] }
|
174
|
-
|
175
|
-
subject { MergePacts.call(pact_hashes) }
|
176
|
-
|
177
|
-
context "when there are no conflicts and no duplicates" do
|
178
|
-
it "adds all the interactions to the merged file" do
|
179
|
-
expect(subject[:interactions].size).to eq 2
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
context "when there is a conflict" do
|
184
|
-
let(:pact_hash_2) do
|
185
|
-
hash = JSON.parse(File.read("spec/fixtures/MyConsumer-MyProvider.json"), symbolize_names: true)
|
186
|
-
hash[:interactions].first[:request][:path] = "/a-different-path"
|
187
|
-
hash
|
188
|
-
end
|
189
|
-
|
190
|
-
it "raises an error with a message that contains the provider states of the conflicting interactions" do
|
191
|
-
expect { subject }.to raise_error PactMergeError, /state 1/
|
192
|
-
end
|
193
|
-
end
|
194
|
-
end
|
195
|
-
end
|
196
|
-
end
|
197
|
-
end
|
198
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
require 'pact_broker/client'
|
4
|
-
|
5
|
-
module PactBroker::Client
|
6
|
-
describe PactBrokerClient do
|
7
|
-
|
8
|
-
let(:client_options) do
|
9
|
-
{ some_option: 'option value'}
|
10
|
-
end
|
11
|
-
let(:base_url) { 'https://blah' }
|
12
|
-
|
13
|
-
describe 'initialize' do
|
14
|
-
subject { PactBrokerClient.new }
|
15
|
-
it 'sets the base_uri to http://pact-broker by default' do
|
16
|
-
expect(subject.base_url).to eq('http://pact-broker')
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'sets the client options to empty hash by default' do
|
20
|
-
expect(subject.client_options).to eq({})
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'allows configuration of the base_uri' do
|
24
|
-
expect(PactBrokerClient.new(base_url: base_url).base_url).to eq(base_url)
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'allows configuration of the client options' do
|
28
|
-
expect(PactBrokerClient.new(client_options: client_options).client_options).to eq(client_options)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe 'pacticipants' do
|
33
|
-
it 'initializes pacticipants with base url and client options' do
|
34
|
-
expect(PactBroker::Client::Pacticipants).to receive(:new).with(base_url: base_url, client_options: client_options)
|
35
|
-
PactBrokerClient.new(base_url: base_url, client_options: client_options).pacticipants
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
describe 'pacts' do
|
40
|
-
it 'initializes [act] with base url and client options' do
|
41
|
-
expect(PactBroker::Client::Pacts).to receive(:new).with(base_url: base_url, client_options: client_options)
|
42
|
-
PactBrokerClient.new(base_url: base_url, client_options: client_options).pacts
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'pact_broker/client/pacticipants/create'
|
2
|
-
|
3
|
-
module PactBroker
|
4
|
-
module Client
|
5
|
-
module Pacticipants2
|
6
|
-
describe Create do
|
7
|
-
describe ".call" do
|
8
|
-
before do
|
9
|
-
allow_any_instance_of(PactBroker::Client::Hal::HttpClient).to receive(:sleep)
|
10
|
-
end
|
11
|
-
let(:pact_broker_client_options) { { pact_broker_base_url: broker_base_url} }
|
12
|
-
let(:broker_base_url) { "http://url" }
|
13
|
-
let(:params) { { name: 'Foo' } }
|
14
|
-
|
15
|
-
subject { Create.call(params, {}, pact_broker_client_options)}
|
16
|
-
|
17
|
-
context "when there is an http error" do
|
18
|
-
let!(:index_request) do
|
19
|
-
stub_request(:get, broker_base_url).to_return(status: 500, body: 'some error', headers: { "Content-Type" => "application/hal+json" } )
|
20
|
-
end
|
21
|
-
|
22
|
-
it "returns a failure result" do
|
23
|
-
expect(subject.success).to be false
|
24
|
-
expect(subject.message).to include 'some error'
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'pact_broker/client/pacticipants'
|
2
|
-
module PactBroker
|
3
|
-
module Client
|
4
|
-
describe Pacticipants do
|
5
|
-
let(:client_options) do
|
6
|
-
{ some_option: 'option value'}
|
7
|
-
end
|
8
|
-
let(:base_url) { 'https://blah' }
|
9
|
-
|
10
|
-
describe 'versions' do
|
11
|
-
it 'initializes versions with base url and client options' do
|
12
|
-
expect(PactBroker::Client::Versions).to receive(:new).with(base_url: base_url, client_options: client_options)
|
13
|
-
Pacticipants.new(base_url: base_url, client_options: client_options).versions
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,272 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'fakefs/safe'
|
3
|
-
require 'pact_broker/client/publish_pacts_the_old_way'
|
4
|
-
require 'json'
|
5
|
-
|
6
|
-
module PactBroker
|
7
|
-
module Client
|
8
|
-
describe PublishPactsTheOldWay do
|
9
|
-
|
10
|
-
# The amount of stubbing that we have to do here indicates this class is doing
|
11
|
-
# TOO MUCH and needs to be split up!
|
12
|
-
before do
|
13
|
-
FakeFS.activate!
|
14
|
-
allow(pacts_client).to receive(:publish).and_return(latest_pact_url)
|
15
|
-
allow(PactBroker::Client::PactBrokerClient).to receive(:new).and_return(pact_broker_client)
|
16
|
-
allow(pact_broker_client).to receive_message_chain(:pacticipants, :versions).and_return(pact_versions_client)
|
17
|
-
allow(pact_broker_client).to receive_message_chain(:pacticipants, :versions, :pacts).and_return(pacts_client)
|
18
|
-
allow(pacts_client).to receive(:version_published?).and_return(false)
|
19
|
-
allow($stdout).to receive(:puts)
|
20
|
-
allow(Retry).to receive(:sleep)
|
21
|
-
allow(MergePacts).to receive(:call) { | pact_hashes | pact_hashes[0] }
|
22
|
-
FileUtils.mkdir_p "spec/pacts"
|
23
|
-
File.open("spec/pacts/consumer-provider.json", "w") { |file| file << pact_hash.to_json }
|
24
|
-
File.open("spec/pacts/consumer-provider-2.json", "w") { |file| file << pact_hash.to_json }
|
25
|
-
File.open("spec/pacts/foo-bar.json", "w") { |file| file << pact_hash_2.to_json }
|
26
|
-
allow_any_instance_of(PublishPactsTheOldWay).to receive(:create_index_entry_point).and_return(index_entry_point)
|
27
|
-
end
|
28
|
-
|
29
|
-
after do
|
30
|
-
FakeFS.deactivate!
|
31
|
-
end
|
32
|
-
|
33
|
-
let(:latest_pact_url) { 'http://example.org/latest/pact' }
|
34
|
-
let(:pact_broker_client) { double("PactBroker::Client")}
|
35
|
-
let(:pact_file_paths) { ['spec/pacts/consumer-provider.json']}
|
36
|
-
let(:consumer_version) { "1.2.3" }
|
37
|
-
let(:tags) { nil }
|
38
|
-
let(:branch) { nil }
|
39
|
-
let(:build_url) { nil }
|
40
|
-
let(:pact_hash) { { consumer: { name: 'Consumer'}, provider: { name: 'Provider' }, interactions: [] } }
|
41
|
-
let(:pact_hash_2) { {consumer: { name: 'Foo' }, provider: { name: 'Bar' }, interactions: [] } }
|
42
|
-
let(:pacts_client) { instance_double("PactBroker::ClientSupport::Pacts")}
|
43
|
-
let(:pact_versions_client) { instance_double("PactBroker::Client::Versions", tag: false) }
|
44
|
-
let(:pact_broker_base_url) { 'http://some-host'}
|
45
|
-
let(:consumer_version_params) do
|
46
|
-
{
|
47
|
-
number: consumer_version,
|
48
|
-
branch: branch,
|
49
|
-
tags: tags,
|
50
|
-
build_url: build_url
|
51
|
-
}
|
52
|
-
end
|
53
|
-
let(:pact_broker_client_options) do
|
54
|
-
{
|
55
|
-
basic_auth: {
|
56
|
-
username: 'user',
|
57
|
-
password: 'pass'
|
58
|
-
}
|
59
|
-
}
|
60
|
-
end
|
61
|
-
let(:index_entry_point) { instance_double("PactBroker::Client::Hal::EntryPoint", :get! => index_resource )}
|
62
|
-
let(:index_resource) { instance_double("PactBroker::Client::Hal::Entity", can?: can_create_version ) }
|
63
|
-
let(:can_create_version) { false }
|
64
|
-
let(:options) { {} }
|
65
|
-
|
66
|
-
subject { PublishPactsTheOldWay.new(pact_broker_base_url, pact_file_paths, consumer_version_params, options, pact_broker_client_options) }
|
67
|
-
|
68
|
-
describe "call" do
|
69
|
-
it "creates a PactBroker Client" do
|
70
|
-
expect(PactBroker::Client::PactBrokerClient).to receive(:new).with(base_url: pact_broker_base_url, client_options: pact_broker_client_options)
|
71
|
-
subject.call
|
72
|
-
end
|
73
|
-
|
74
|
-
it "uses the pact_broker client to publish the given pact" do
|
75
|
-
expect(pacts_client).to receive(:publish).with(pact_hash: pact_hash, consumer_version: consumer_version)
|
76
|
-
subject.call
|
77
|
-
end
|
78
|
-
|
79
|
-
context "when publishing is successful" do
|
80
|
-
it "puts the location of the latest pact" do
|
81
|
-
allow($stdout).to receive(:puts)
|
82
|
-
expect($stdout).to receive(:puts).with(/#{latest_pact_url}/)
|
83
|
-
subject.call
|
84
|
-
end
|
85
|
-
|
86
|
-
it "returns true" do
|
87
|
-
expect(subject.call.success).to eq true
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
context "when publishing multiple files with the same consumer/provider" do
|
92
|
-
let(:pact_file_paths) { ['spec/pacts/consumer-provider.json','spec/pacts/consumer-provider-2.json']}
|
93
|
-
it "merges the files" do
|
94
|
-
expect(MergePacts).to receive(:call).with([pact_hash, pact_hash])
|
95
|
-
subject.call
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
context "when publishing multiple files with different consumers" do
|
100
|
-
let(:pact_file_paths) { ['spec/pacts/consumer-provider.json','spec/pacts/foo-bar.json']}
|
101
|
-
let(:tags) { ['dev'] }
|
102
|
-
|
103
|
-
it "tags each consumer" do
|
104
|
-
expect(pact_versions_client).to receive(:tag).with(
|
105
|
-
pacticipant: "Consumer",
|
106
|
-
version: consumer_version,
|
107
|
-
tag: "dev"
|
108
|
-
)
|
109
|
-
expect(pact_versions_client).to receive(:tag).with(
|
110
|
-
pacticipant: "Foo",
|
111
|
-
version: consumer_version,
|
112
|
-
tag: "dev"
|
113
|
-
)
|
114
|
-
subject.call
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
context "when publishing one or more pacts fails" do
|
119
|
-
let(:pact_file_paths) { ['spec/pacts/consumer-provider.json','spec/pacts/foo-bar.json']}
|
120
|
-
|
121
|
-
before do
|
122
|
-
allow(pacts_client).to receive(:publish).with(
|
123
|
-
pact_hash: pact_hash,
|
124
|
-
consumer_version: consumer_version
|
125
|
-
).and_raise("an error")
|
126
|
-
|
127
|
-
allow($stderr).to receive(:puts)
|
128
|
-
end
|
129
|
-
|
130
|
-
it "logs an message to stderr" do
|
131
|
-
expect($stderr).to receive(:puts).with(/Failed to publish Consumer\/Provider pact/)
|
132
|
-
subject.call
|
133
|
-
end
|
134
|
-
|
135
|
-
it "continues publishing the rest" do
|
136
|
-
expect(pacts_client).to receive(:publish).with(
|
137
|
-
pact_hash: pact_hash_2, consumer_version: consumer_version)
|
138
|
-
subject.call
|
139
|
-
end
|
140
|
-
|
141
|
-
it "returns false" do
|
142
|
-
expect(subject.call.success).to be false
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
context "when no pact files are specified" do
|
147
|
-
let(:pact_file_paths) { [] }
|
148
|
-
it "raises a validation error" do
|
149
|
-
expect { subject.call }.to raise_error(/No pact files found/)
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
context "when consumer_version is blank" do
|
154
|
-
let(:consumer_version) { " " }
|
155
|
-
it "raises a validation error" do
|
156
|
-
expect { subject.call }.to raise_error(/Please specify the consumer_version/)
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
context "when consumer_version has a new line" do
|
161
|
-
let(:consumer_version) { "1\n" }
|
162
|
-
|
163
|
-
it "strips the new line" do
|
164
|
-
expect(pacts_client).to receive(:publish).with(pact_hash: pact_hash, consumer_version: "1")
|
165
|
-
subject.call
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
context "when pact_broker_base_url is blank" do
|
170
|
-
let(:pact_broker_base_url) { " " }
|
171
|
-
it "raises a validation errror" do
|
172
|
-
expect { subject.call }.to raise_error(/Please specify the pact_broker_base_url/)
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
context "when a tag is provided" do
|
177
|
-
let(:tags) { ["dev"] }
|
178
|
-
|
179
|
-
it "tags the consumer version" do
|
180
|
-
expect(pact_versions_client).to receive(:tag).with({pacticipant: "Consumer",
|
181
|
-
version: consumer_version, tag: "dev"})
|
182
|
-
subject.call
|
183
|
-
end
|
184
|
-
|
185
|
-
it "tags the version before publishing the pact so that there aren't timing issues retrieving pacts by tag" do
|
186
|
-
expect(pact_versions_client).to receive(:tag).ordered
|
187
|
-
expect(pacts_client).to receive(:publish).ordered
|
188
|
-
subject.call
|
189
|
-
end
|
190
|
-
|
191
|
-
context "when the tag has a new line on the end of it" do
|
192
|
-
let(:tags) { ["foo\n"] }
|
193
|
-
|
194
|
-
it "strips the newline" do
|
195
|
-
expect(pact_versions_client).to receive(:tag).with({pacticipant: "Consumer",
|
196
|
-
version: consumer_version, tag: "foo"})
|
197
|
-
subject.call
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
|
-
context "when an error occurs tagging the pact" do
|
202
|
-
before do
|
203
|
-
allow(pact_versions_client).to receive(:tag).and_raise("an error")
|
204
|
-
allow(Retry).to receive(:sleep)
|
205
|
-
allow($stderr).to receive(:puts)
|
206
|
-
end
|
207
|
-
|
208
|
-
it "retries multiple times" do
|
209
|
-
expect(pact_versions_client).to receive(:tag).exactly(3).times
|
210
|
-
subject.call
|
211
|
-
end
|
212
|
-
|
213
|
-
it "returns false" do
|
214
|
-
expect(subject.call.success).to eq false
|
215
|
-
end
|
216
|
-
end
|
217
|
-
end
|
218
|
-
|
219
|
-
context "when an error occurs every time while publishing a pact" do
|
220
|
-
before do
|
221
|
-
allow(Retry).to receive(:sleep)
|
222
|
-
allow(pacts_client).to receive(:publish).and_raise("an error")
|
223
|
-
allow($stderr).to receive(:puts)
|
224
|
-
end
|
225
|
-
|
226
|
-
it "retries multiple times" do
|
227
|
-
expect(pacts_client).to receive(:publish).exactly(3).times
|
228
|
-
subject.call
|
229
|
-
end
|
230
|
-
|
231
|
-
it "returns false" do
|
232
|
-
expect(subject.call.success).to eq false
|
233
|
-
end
|
234
|
-
end
|
235
|
-
|
236
|
-
context "when an error occurs less than the maximum number of retries" do
|
237
|
-
before do
|
238
|
-
allow(Retry).to receive(:sleep)
|
239
|
-
tries = 0
|
240
|
-
allow(pacts_client).to receive(:publish) do
|
241
|
-
if tries == 0
|
242
|
-
tries += 1
|
243
|
-
raise "an error"
|
244
|
-
else
|
245
|
-
latest_pact_url
|
246
|
-
end
|
247
|
-
end
|
248
|
-
allow($stderr).to receive(:puts)
|
249
|
-
end
|
250
|
-
|
251
|
-
it "retries multiple times" do
|
252
|
-
expect(pacts_client).to receive(:publish).exactly(2).times
|
253
|
-
subject.call
|
254
|
-
end
|
255
|
-
|
256
|
-
it "returns true" do
|
257
|
-
expect(subject.call.success).to eq true
|
258
|
-
end
|
259
|
-
end
|
260
|
-
|
261
|
-
context "when the broker does not support creation of a version with a branch but a branch is specified" do
|
262
|
-
let(:branch) { "main" }
|
263
|
-
|
264
|
-
it "logs a warning" do
|
265
|
-
expect($stdout).to receive(:puts).with(/WARN: This version/)
|
266
|
-
subject.call
|
267
|
-
end
|
268
|
-
end
|
269
|
-
end
|
270
|
-
end
|
271
|
-
end
|
272
|
-
end
|
@@ -1,119 +0,0 @@
|
|
1
|
-
require 'pact_broker/client/retry'
|
2
|
-
|
3
|
-
module PactBroker
|
4
|
-
module Client
|
5
|
-
describe Retry do
|
6
|
-
describe ".until_truthy_or_max_times" do
|
7
|
-
before do
|
8
|
-
allow(service).to receive(:get_result).and_return(1, 2, 3)
|
9
|
-
allow(condition).to receive(:call).and_return(false, false, true)
|
10
|
-
allow(Retry).to receive(:sleep)
|
11
|
-
end
|
12
|
-
|
13
|
-
let(:service) { double('service') }
|
14
|
-
let(:condition) { double('condition') }
|
15
|
-
let(:times) { 4 }
|
16
|
-
let(:sleep_first) { nil }
|
17
|
-
|
18
|
-
subject do
|
19
|
-
Retry.until_truthy_or_max_times(condition: condition, times: times, sleep: 3, sleep_first: sleep_first) do
|
20
|
-
service.get_result
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
context "times is 0 (which it shouldn't be, but just to be sure...)" do
|
25
|
-
let(:times) { 0 }
|
26
|
-
|
27
|
-
it "only executes the block once" do
|
28
|
-
subject
|
29
|
-
expect(service).to have_received(:get_result).exactly(1).times
|
30
|
-
end
|
31
|
-
|
32
|
-
it "does not execute the condition" do
|
33
|
-
expect(condition).to_not receive(:call)
|
34
|
-
subject
|
35
|
-
end
|
36
|
-
|
37
|
-
it "returns the result" do
|
38
|
-
expect(subject).to eq 1
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
context "times is 1" do
|
43
|
-
let(:times) { 1 }
|
44
|
-
|
45
|
-
it "only executes the block once" do
|
46
|
-
subject
|
47
|
-
expect(service).to have_received(:get_result).exactly(1).times
|
48
|
-
end
|
49
|
-
|
50
|
-
it "does not execute the condition" do
|
51
|
-
expect(condition).to_not receive(:call)
|
52
|
-
subject
|
53
|
-
end
|
54
|
-
|
55
|
-
it "returns the result" do
|
56
|
-
expect(subject).to eq 1
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
context "when the condition becomes true before the max tries" do
|
61
|
-
it "stops retrying when the condition becomes true" do
|
62
|
-
subject
|
63
|
-
expect(condition).to have_received(:call).exactly(3).times
|
64
|
-
expect(service).to have_received(:get_result).exactly(3).times
|
65
|
-
end
|
66
|
-
|
67
|
-
it "returns the most recent result" do
|
68
|
-
expect(subject).to eq 3
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
context "when the max tries is reached before the condition becomes true" do
|
73
|
-
let(:times) { 2 }
|
74
|
-
|
75
|
-
it "stops retrying once the max tries is reached" do
|
76
|
-
subject
|
77
|
-
expect(condition).to have_received(:call).exactly(2).times
|
78
|
-
expect(service).to have_received(:get_result).exactly(2).times
|
79
|
-
end
|
80
|
-
|
81
|
-
it "returns the most recent result" do
|
82
|
-
expect(subject).to eq 2
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
context "when an error is raised each time" do
|
87
|
-
TestError = Class.new(StandardError)
|
88
|
-
|
89
|
-
before do
|
90
|
-
allow(service).to receive(:get_result).and_raise(TestError)
|
91
|
-
allow($stderr).to receive(:puts)
|
92
|
-
end
|
93
|
-
|
94
|
-
it "stops retrying once the max tries is reached" do
|
95
|
-
begin
|
96
|
-
subject
|
97
|
-
rescue TestError
|
98
|
-
end
|
99
|
-
expect(service).to have_received(:get_result).exactly(4).times
|
100
|
-
end
|
101
|
-
|
102
|
-
it "raises the error" do
|
103
|
-
expect { subject }.to raise_error TestError
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
context "when sleep_first is true" do
|
108
|
-
let(:sleep_first) { true }
|
109
|
-
|
110
|
-
it "sleeps before it executes the block" do
|
111
|
-
expect(Retry).to receive(:sleep).ordered
|
112
|
-
expect(service).to receive(:get_result).ordered
|
113
|
-
subject
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|