pact_broker-client 1.73.0 → 1.75.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/release_gem.yml +2 -2
- data/.github/workflows/test.yml +4 -1
- data/.github/workflows/trigger_pact_docs_update.yml +1 -1
- data/CHANGELOG.md +22 -0
- data/Gemfile +1 -0
- data/README.md +100 -35
- data/doc/pacts/markdown/Pact Broker Client - Pact Broker.md +45 -0
- data/doc/pacts/markdown/Pact Broker Client - Pactflow.md +1 -1
- data/example/scripts/publish-pact-rake.sh +10 -0
- data/example/scripts/publish-pact.sh +25 -1
- data/example/scripts/publish-provider-contract.sh +2 -1
- data/lib/pact_broker/client/branches/delete_branch.rb +64 -0
- data/lib/pact_broker/client/cli/branch_commands.rb +40 -0
- data/lib/pact_broker/client/cli/broker.rb +2 -1
- data/lib/pact_broker/client/cli/custom_thor.rb +2 -2
- data/lib/pact_broker/client/cli/environment_commands.rb +1 -1
- data/lib/pact_broker/client/cli/pact_commands.rb +35 -14
- data/lib/pact_broker/client/cli/version_commands.rb +2 -2
- data/lib/pact_broker/client/git.rb +20 -3
- data/lib/pact_broker/client/merge_pacts.rb +5 -2
- data/lib/pact_broker/client/publish_pacts_the_old_way.rb +1 -1
- data/lib/pact_broker/client/tasks/publication_task.rb +40 -23
- data/lib/pact_broker/client/version.rb +1 -1
- data/lib/pactflow/client/cli/provider_contract_commands.rb +1 -1
- data/lib/pactflow/client/provider_contracts/publish.rb +1 -1
- data/script/publish-provider-contract.sh +0 -1
- data/script/update-cli-usage-in-readme.rb +1 -0
- data/spec/fixtures/MyConsumer-MyProvider (1).json +37 -0
- data/spec/fixtures/MyConsumer-MyProvider.json +37 -0
- data/spec/integration/can_i_deploy_spec.rb +0 -9
- data/spec/lib/pact_broker/client/branches/delete_branch_spec.rb +103 -0
- data/spec/lib/pact_broker/client/cli/broker_publish_spec.rb +38 -21
- data/spec/lib/pact_broker/client/merge_pacts_spec.rb +26 -0
- data/spec/lib/pact_broker/client/publish_pacts_the_old_way_spec.rb +1 -3
- data/spec/lib/pact_broker/client/tasks/publication_task_spec.rb +54 -31
- data/spec/pacts/pact_broker_client-pact_broker.json +43 -0
- data/spec/pacts/pact_broker_client-pactflow.json +1 -1
- data/spec/service_providers/delete_branch_spec.rb +68 -0
- data/spec/service_providers/pact_helper.rb +1 -0
- data/spec/service_providers/pactflow_publish_provider_contract_spec.rb +1 -1
- data/spec/support/ssl_server.rb +1 -1
- data/tasks/pact.rake +79 -0
- metadata +14 -3
@@ -4,10 +4,12 @@ require 'pact_broker/client/git'
|
|
4
4
|
|
5
5
|
module PactBroker::Client::CLI
|
6
6
|
describe Broker do
|
7
|
-
describe
|
7
|
+
describe '.broker' do
|
8
8
|
before do
|
9
9
|
allow(PactBroker::Client::PublishPacts).to receive(:call).and_return(result)
|
10
|
-
allow(PactBroker::Client::Git).to receive(:branch).and_return(
|
10
|
+
allow(PactBroker::Client::Git).to receive(:branch).and_return('bar')
|
11
|
+
allow(PactBroker::Client::Git).to receive(:commit).and_return('6.6.6')
|
12
|
+
allow(PactBroker::Client::Git).to receive(:build_url).and_return('build_url')
|
11
13
|
subject.options = OpenStruct.new(minimum_valid_options)
|
12
14
|
allow($stdout).to receive(:puts)
|
13
15
|
end
|
@@ -30,7 +32,7 @@ module PactBroker::Client::CLI
|
|
30
32
|
expect(PactBroker::Client::PublishPacts).to receive(:call).with(
|
31
33
|
"http://pact-broker",
|
32
34
|
["spec/support/cli_test_pacts/foo.json"],
|
33
|
-
{ number: "1.2.3", tags: []
|
35
|
+
{ number: "1.2.3", tags: [] },
|
34
36
|
{},
|
35
37
|
{ pact_broker_base_url: 'http://pact-broker' }
|
36
38
|
)
|
@@ -151,7 +153,7 @@ module PactBroker::Client::CLI
|
|
151
153
|
expect(PactBroker::Client::PublishPacts).to receive(:call).with(
|
152
154
|
anything,
|
153
155
|
anything,
|
154
|
-
hash_including(branch: "main"
|
156
|
+
hash_including(branch: "main"),
|
155
157
|
anything,
|
156
158
|
anything
|
157
159
|
)
|
@@ -159,50 +161,55 @@ module PactBroker::Client::CLI
|
|
159
161
|
end
|
160
162
|
end
|
161
163
|
|
162
|
-
context "with --auto-detect-version-properties
|
164
|
+
context "with --auto-detect-version-properties specified" do
|
163
165
|
before do
|
164
166
|
subject.options = OpenStruct.new(
|
165
|
-
minimum_valid_options.merge(auto_detect_version_properties: true)
|
167
|
+
minimum_valid_options.merge(auto_detect_version_properties: true, consumer_app_version: nil)
|
166
168
|
)
|
167
|
-
allow(subject).to receive(:explict_auto_detect_version_properties).and_return(false)
|
168
169
|
end
|
169
170
|
|
170
171
|
it "determines the git branch name" do
|
171
|
-
expect(PactBroker::Client::Git).to receive(:branch).with(raise_error:
|
172
|
+
expect(PactBroker::Client::Git).to receive(:branch).with(raise_error: true)
|
172
173
|
invoke_broker
|
173
174
|
end
|
174
175
|
|
175
|
-
it "passes in the auto detected branch option
|
176
|
+
it "passes in the auto detected branch option" do
|
176
177
|
expect(PactBroker::Client::PublishPacts).to receive(:call).with(
|
177
178
|
anything,
|
178
179
|
anything,
|
179
|
-
hash_including(branch: "bar"
|
180
|
+
hash_including(branch: "bar"),
|
180
181
|
anything,
|
181
182
|
anything
|
182
183
|
)
|
183
184
|
invoke_broker
|
184
185
|
end
|
185
|
-
end
|
186
186
|
|
187
|
+
it 'determines the commit sha' do
|
188
|
+
expect(PactBroker::Client::Git).to receive(:commit).with(raise_error: true)
|
189
|
+
invoke_broker
|
190
|
+
end
|
187
191
|
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
+
it 'passes in the auto detected commit sha option' do
|
193
|
+
expect(PactBroker::Client::PublishPacts).to receive(:call).with(
|
194
|
+
anything,
|
195
|
+
anything,
|
196
|
+
hash_including(number: '6.6.6'),
|
197
|
+
anything,
|
198
|
+
anything
|
192
199
|
)
|
193
|
-
|
200
|
+
invoke_broker
|
194
201
|
end
|
195
202
|
|
196
|
-
it
|
197
|
-
expect(PactBroker::Client::Git).to receive(:
|
203
|
+
it 'determines the build URL' do
|
204
|
+
expect(PactBroker::Client::Git).to receive(:build_url)
|
198
205
|
invoke_broker
|
199
206
|
end
|
200
207
|
|
201
|
-
it
|
208
|
+
it 'passes in the auto detected build URL' do
|
202
209
|
expect(PactBroker::Client::PublishPacts).to receive(:call).with(
|
203
210
|
anything,
|
204
211
|
anything,
|
205
|
-
hash_including(
|
212
|
+
hash_including(build_url: 'build_url'),
|
206
213
|
anything,
|
207
214
|
anything
|
208
215
|
)
|
@@ -220,7 +227,7 @@ module PactBroker::Client::CLI
|
|
220
227
|
expect(PactBroker::Client::PublishPacts).to receive(:call).with(
|
221
228
|
anything,
|
222
229
|
anything,
|
223
|
-
hash_including(branch: "specified-branch"
|
230
|
+
hash_including(branch: "specified-branch"),
|
224
231
|
anything,
|
225
232
|
anything
|
226
233
|
)
|
@@ -248,6 +255,16 @@ module PactBroker::Client::CLI
|
|
248
255
|
end
|
249
256
|
end
|
250
257
|
|
258
|
+
context "with no consumer_app_version" do
|
259
|
+
before do
|
260
|
+
subject.options.consumer_app_version = nil
|
261
|
+
end
|
262
|
+
|
263
|
+
it "raises an error" do
|
264
|
+
expect { invoke_broker }.to raise_error ::Thor::RequiredArgumentMissingError, /--consumer-app-version/
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
251
268
|
context "with basic auth options specified" do
|
252
269
|
before do
|
253
270
|
subject.options = OpenStruct.new(
|
@@ -166,6 +166,32 @@ module PactBroker
|
|
166
166
|
expect(subject).to eq expected_merge
|
167
167
|
end
|
168
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
|
169
195
|
end
|
170
196
|
end
|
171
197
|
end
|
@@ -37,7 +37,6 @@ module PactBroker
|
|
37
37
|
let(:tags) { nil }
|
38
38
|
let(:branch) { nil }
|
39
39
|
let(:build_url) { nil }
|
40
|
-
let(:version_required) { false }
|
41
40
|
let(:pact_hash) { { consumer: { name: 'Consumer'}, provider: { name: 'Provider' }, interactions: [] } }
|
42
41
|
let(:pact_hash_2) { {consumer: { name: 'Foo' }, provider: { name: 'Bar' }, interactions: [] } }
|
43
42
|
let(:pacts_client) { instance_double("PactBroker::ClientSupport::Pacts")}
|
@@ -48,8 +47,7 @@ module PactBroker
|
|
48
47
|
number: consumer_version,
|
49
48
|
branch: branch,
|
50
49
|
tags: tags,
|
51
|
-
build_url: build_url
|
52
|
-
version_required: version_required
|
50
|
+
build_url: build_url
|
53
51
|
}
|
54
52
|
end
|
55
53
|
let(:pact_broker_client_options) do
|
@@ -5,7 +5,6 @@ require 'pact_broker/client/command_result'
|
|
5
5
|
|
6
6
|
module PactBroker::Client
|
7
7
|
describe PublicationTask do
|
8
|
-
|
9
8
|
before do
|
10
9
|
@consumer_version = "1.2.3"
|
11
10
|
end
|
@@ -19,6 +18,8 @@ module PactBroker::Client
|
|
19
18
|
allow(PactBroker::Client::PublishPacts).to receive(:new).and_return(publish_pacts)
|
20
19
|
allow(FileList).to receive(:[]).with(pattern).and_return(pact_file_list)
|
21
20
|
allow(PactBroker::Client::Git).to receive(:branch).and_return('foo')
|
21
|
+
allow(PactBroker::Client::Git).to receive(:commit).and_return('6.6.6')
|
22
|
+
allow(PactBroker::Client::Git).to receive(:build_url).and_return("build_url")
|
22
23
|
allow($stdout).to receive(:puts)
|
23
24
|
end
|
24
25
|
|
@@ -33,7 +34,7 @@ module PactBroker::Client
|
|
33
34
|
|
34
35
|
context "when pacts are succesfully published" do
|
35
36
|
it "invokes PublishPacts with the default values" do
|
36
|
-
expect(PactBroker::Client::PublishPacts).to receive(:new).with('http://pact-broker', pact_file_list, { number: '1.2.3', branch: "foo", tags: []
|
37
|
+
expect(PactBroker::Client::PublishPacts).to receive(:new).with('http://pact-broker', pact_file_list, { number: '1.2.3', branch: "foo", tags: [] }, {}, {}).and_return(publish_pacts)
|
37
38
|
expect(publish_pacts).to receive(:call).and_return(result)
|
38
39
|
Rake::Task['pact:publish'].execute
|
39
40
|
end
|
@@ -57,7 +58,7 @@ module PactBroker::Client
|
|
57
58
|
end
|
58
59
|
|
59
60
|
it "invokes PublishPacts with the write method set" do
|
60
|
-
expect(PactBroker::Client::PublishPacts).to receive(:new).with('http://pact-broker', pact_file_list, { number: "1.2.3", branch: "foo", tags: []
|
61
|
+
expect(PactBroker::Client::PublishPacts).to receive(:new).with('http://pact-broker', pact_file_list, { number: "1.2.3", branch: "foo", tags: [] }, {}, {write: :merge}).and_return(publish_pacts)
|
61
62
|
expect(publish_pacts).to receive(:call).and_return(result)
|
62
63
|
Rake::Task['pact:publish:merge'].execute
|
63
64
|
end
|
@@ -87,81 +88,92 @@ module PactBroker::Client
|
|
87
88
|
context "when auto_detect_version_properties is explicitly set to true" do
|
88
89
|
before :all do
|
89
90
|
PactBroker::Client::PublicationTask.new(:git_branch_auto_detect_true) do | task |
|
90
|
-
task.consumer_version = '1.2.3'
|
91
91
|
task.auto_detect_version_properties = true
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
|
-
|
95
|
+
# Don't usually put 3 expects into the one it block, but if I separate them,
|
96
|
+
# only the first it block passes for some reason that I can't work out.
|
97
|
+
it "gets the commit, build_url and branch" do
|
98
|
+
expect(PactBroker::Client::Git).to receive(:commit).with(raise_error: true)
|
99
|
+
expect(PactBroker::Client::Git).to receive(:build_url)
|
96
100
|
expect(PactBroker::Client::Git).to receive(:branch).with(raise_error: true)
|
97
101
|
Rake::Task['pact:publish:git_branch_auto_detect_true'].execute
|
98
102
|
end
|
99
103
|
|
100
|
-
it "invokes PublishPacts with the branch name" do
|
101
|
-
expect(PactBroker::Client::PublishPacts).to receive(:new).with(anything, anything, hash_including(branch: "foo"), anything, anything).and_return(publish_pacts)
|
104
|
+
it "invokes PublishPacts with the branch name and build URL" do
|
105
|
+
expect(PactBroker::Client::PublishPacts).to receive(:new).with(anything, anything, hash_including(number: "6.6.6", branch: "foo", build_url: "build_url"), anything, anything).and_return(publish_pacts)
|
102
106
|
Rake::Task['pact:publish:git_branch_auto_detect_true'].execute
|
103
107
|
end
|
104
108
|
end
|
105
109
|
|
106
|
-
context "when auto_detect_version_properties is explicitly set to true and the
|
110
|
+
context "when auto_detect_version_properties is explicitly set to true and the auto detectable attributes are specified" do
|
107
111
|
before :all do
|
108
|
-
PactBroker::Client::PublicationTask.new(:
|
109
|
-
task.consumer_version = '1.2.3'
|
112
|
+
PactBroker::Client::PublicationTask.new(:auto_detect_true_with_attributes_specified) do | task |
|
110
113
|
task.auto_detect_version_properties = true
|
111
|
-
task.
|
114
|
+
task.consumer_version = '1.2.3'
|
115
|
+
task.branch = "feat/foo"
|
116
|
+
task.consumer_version = "3"
|
117
|
+
task.build_url = "some_build"
|
112
118
|
end
|
113
119
|
end
|
114
120
|
|
115
|
-
it "does not get the branch
|
121
|
+
it "does not get the commit, branch or build URL from Git" do
|
122
|
+
expect(PactBroker::Client::Git).to_not receive(:commit)
|
123
|
+
expect(PactBroker::Client::Git).to_not receive(:build_url)
|
116
124
|
expect(PactBroker::Client::Git).to_not receive(:branch)
|
117
|
-
Rake::Task['pact:publish:
|
125
|
+
Rake::Task['pact:publish:auto_detect_true_with_attributes_specified'].execute
|
118
126
|
end
|
119
127
|
|
120
|
-
it "invokes PublishPacts with the specified
|
121
|
-
expect(PactBroker::Client::PublishPacts).to receive(:new).with(anything, anything, hash_including(branch: "
|
122
|
-
Rake::Task['pact:publish:
|
128
|
+
it "invokes PublishPacts with the specified attributes" do
|
129
|
+
expect(PactBroker::Client::PublishPacts).to receive(:new).with(anything, anything, hash_including(number: "3", branch: "feat/foo", build_url: "some_build"), anything, anything).and_return(publish_pacts)
|
130
|
+
Rake::Task['pact:publish:auto_detect_true_with_attributes_specified'].execute
|
123
131
|
end
|
124
132
|
end
|
125
133
|
|
126
134
|
context "when auto_detect_version_properties is explicitly set to false" do
|
127
135
|
before :all do
|
128
|
-
PactBroker::Client::PublicationTask.new(:
|
129
|
-
task.consumer_version = '1.2.3'
|
136
|
+
PactBroker::Client::PublicationTask.new(:auto_detect_false) do | task |
|
130
137
|
task.auto_detect_version_properties = false
|
138
|
+
task.consumer_version = '1.2.3'
|
139
|
+
task.branch = "feat/foo"
|
140
|
+
task.consumer_version = "3"
|
141
|
+
task.build_url = "some_build"
|
131
142
|
end
|
132
143
|
end
|
133
144
|
|
134
|
-
it "does not get the
|
145
|
+
it "does not get the commit, branch or build URL from Git" do
|
146
|
+
expect(PactBroker::Client::Git).to_not receive(:commit)
|
147
|
+
expect(PactBroker::Client::Git).to_not receive(:build_url)
|
135
148
|
expect(PactBroker::Client::Git).to_not receive(:branch)
|
136
|
-
Rake::Task['pact:publish:
|
149
|
+
Rake::Task['pact:publish:auto_detect_false'].execute
|
137
150
|
end
|
138
151
|
|
139
|
-
it "invokes PublishPacts
|
140
|
-
expect(PactBroker::Client::PublishPacts).to receive(:new).with(anything, anything,
|
141
|
-
Rake::Task['pact:publish:
|
152
|
+
it "invokes PublishPacts with the specified attributes" do
|
153
|
+
expect(PactBroker::Client::PublishPacts).to receive(:new).with(anything, anything, hash_including(number: "3", branch: "feat/foo", build_url: "some_build"), anything, anything).and_return(publish_pacts)
|
154
|
+
Rake::Task['pact:publish:auto_detect_false'].execute
|
142
155
|
end
|
143
156
|
end
|
144
157
|
|
145
|
-
context "when auto_detect_version_properties is left as its default" do
|
158
|
+
context "when auto_detect_version_properties is left as its default and the branch is not specified" do
|
146
159
|
before :all do
|
147
|
-
PactBroker::Client::PublicationTask.new(:
|
160
|
+
PactBroker::Client::PublicationTask.new(:auto_detect_default) do | task |
|
148
161
|
task.consumer_version = '1.2.3'
|
149
162
|
end
|
150
163
|
end
|
151
164
|
|
152
|
-
it "gets the git branch name" do
|
165
|
+
it "gets the git branch name but won't raise an error if it can't be determined" do
|
153
166
|
expect(PactBroker::Client::Git).to receive(:branch).with(raise_error: false)
|
154
|
-
Rake::Task['pact:publish:
|
167
|
+
Rake::Task['pact:publish:auto_detect_default'].execute
|
155
168
|
end
|
156
169
|
|
157
|
-
it "invokes PublishPacts with the branch name" do
|
170
|
+
it "invokes PublishPacts with the branch name if found" do
|
158
171
|
expect(PactBroker::Client::PublishPacts).to receive(:new).with(anything, anything, hash_including(branch: "foo"),anything, anything).and_return(publish_pacts)
|
159
|
-
Rake::Task['pact:publish:
|
172
|
+
Rake::Task['pact:publish:auto_detect_default'].execute
|
160
173
|
end
|
161
174
|
end
|
162
175
|
|
163
176
|
describe "custom task" do
|
164
|
-
|
165
177
|
before :all do
|
166
178
|
@pact_broker_base_url = "http://some-host"
|
167
179
|
@pattern = "pact/*.json"
|
@@ -184,7 +196,7 @@ module PactBroker::Client
|
|
184
196
|
expect(PactBroker::Client::PublishPacts).to receive(:new).with(
|
185
197
|
@pact_broker_base_url,
|
186
198
|
pact_file_list,
|
187
|
-
{ number: "1.2.3", tags: [@tag], branch: "foo"
|
199
|
+
{ number: "1.2.3", tags: [@tag], branch: "foo" },
|
188
200
|
{},
|
189
201
|
{ basic_auth: @pact_broker_basic_auth, token: @pact_broker_token }
|
190
202
|
)
|
@@ -193,6 +205,17 @@ module PactBroker::Client
|
|
193
205
|
end
|
194
206
|
end
|
195
207
|
|
208
|
+
describe "with no consumer version" do
|
209
|
+
before :all do
|
210
|
+
PactBroker::Client::PublicationTask.new(:no_consumer_version) do
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
it "raises an error" do
|
215
|
+
expect { Rake::Task['pact:publish:no_consumer_version'].execute }.to raise_error PactBroker::Client::Error, /consumer version/
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
196
219
|
describe "timing of block execution" do
|
197
220
|
before :all do
|
198
221
|
PactBroker::Client::PublicationTask.new(:exception) do | task |
|
@@ -6,6 +6,49 @@
|
|
6
6
|
"name": "Pact Broker"
|
7
7
|
},
|
8
8
|
"interactions": [
|
9
|
+
{
|
10
|
+
"description": "a request for the index resource",
|
11
|
+
"providerState": "the pb:pacticipant-branch relation exists in the index resource",
|
12
|
+
"request": {
|
13
|
+
"method": "GET",
|
14
|
+
"path": "/",
|
15
|
+
"headers": {
|
16
|
+
"Accept": "application/hal+json"
|
17
|
+
}
|
18
|
+
},
|
19
|
+
"response": {
|
20
|
+
"status": 200,
|
21
|
+
"headers": {
|
22
|
+
"Content-Type": "application/hal+json;charset=utf-8"
|
23
|
+
},
|
24
|
+
"body": {
|
25
|
+
"_links": {
|
26
|
+
"pb:pacticipant-branch": {
|
27
|
+
"href": "http://localhost:1234/HAL-REL-PLACEHOLDER-PB-PACTICIPANT-BRANCH-{pacticipant}-{branch}"
|
28
|
+
}
|
29
|
+
}
|
30
|
+
},
|
31
|
+
"matchingRules": {
|
32
|
+
"$.body._links.pb:pacticipant-branch.href": {
|
33
|
+
"match": "regex",
|
34
|
+
"regex": "http:\\/\\/.*{pacticipant}.*{branch}"
|
35
|
+
}
|
36
|
+
}
|
37
|
+
}
|
38
|
+
},
|
39
|
+
{
|
40
|
+
"description": "a request to delete a pacticipant branch",
|
41
|
+
"providerState": "a branch named main exists for pacticipant Foo",
|
42
|
+
"request": {
|
43
|
+
"method": "DELETE",
|
44
|
+
"path": "/HAL-REL-PLACEHOLDER-PB-PACTICIPANT-BRANCH-Foo-main"
|
45
|
+
},
|
46
|
+
"response": {
|
47
|
+
"status": 204,
|
48
|
+
"headers": {
|
49
|
+
}
|
50
|
+
}
|
51
|
+
},
|
9
52
|
{
|
10
53
|
"description": "a request to list the latest pacts",
|
11
54
|
"providerState": "a pact between Condor and the Pricing Service exists",
|
@@ -43,7 +43,7 @@
|
|
43
43
|
"path": "/HAL-REL-PLACEHOLDER-PF-PUBLISH-PROVIDER-CONTRACT-Bar",
|
44
44
|
"headers": {
|
45
45
|
"Content-Type": "application/json",
|
46
|
-
"Accept": "application/hal+json"
|
46
|
+
"Accept": "application/hal+json,application/problem+json"
|
47
47
|
},
|
48
48
|
"body": {
|
49
49
|
"pacticipantVersionNumber": "1",
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require "service_providers/pact_helper"
|
2
|
+
require "pact_broker/client/branches/delete_branch"
|
3
|
+
|
4
|
+
RSpec.describe "delete a branch", pact: true do
|
5
|
+
include_context "pact broker"
|
6
|
+
include PactBrokerPactHelperMethods
|
7
|
+
|
8
|
+
let(:params) do
|
9
|
+
{
|
10
|
+
pacticipant: "Foo",
|
11
|
+
branch: "main",
|
12
|
+
error_when_not_found: true
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
let(:options) do
|
17
|
+
{
|
18
|
+
verbose: verbose
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
let(:pact_broker_base_url) { pact_broker.mock_service_base_url }
|
23
|
+
let(:pact_broker_client_options) { { pact_broker_base_url: pact_broker_base_url } }
|
24
|
+
let(:response_headers) { { "Content-Type" => "application/hal+json"} }
|
25
|
+
let(:verbose) { false }
|
26
|
+
|
27
|
+
subject { PactBroker::Client::Branches::DeleteBranch.call(params, options, pact_broker_client_options) }
|
28
|
+
|
29
|
+
def mock_index
|
30
|
+
pact_broker
|
31
|
+
.given("the pb:pacticipant-branch relation exists in the index resource")
|
32
|
+
.upon_receiving("a request for the index resource")
|
33
|
+
.with(
|
34
|
+
method: "GET",
|
35
|
+
path: '/',
|
36
|
+
headers: get_request_headers).
|
37
|
+
will_respond_with(
|
38
|
+
status: 200,
|
39
|
+
headers: pact_broker_response_headers,
|
40
|
+
body: {
|
41
|
+
_links: {
|
42
|
+
:'pb:pacticipant-branch' => {
|
43
|
+
href: placeholder_url_term("pb:pacticipant-branch", ["pacticipant", "branch"], pact_broker)
|
44
|
+
}
|
45
|
+
}
|
46
|
+
}
|
47
|
+
)
|
48
|
+
end
|
49
|
+
|
50
|
+
def mock_branch_delete_request
|
51
|
+
pact_broker
|
52
|
+
.given("a branch named main exists for pacticipant Foo")
|
53
|
+
.upon_receiving("a request to delete a pacticipant branch")
|
54
|
+
.with(
|
55
|
+
method: "DELETE",
|
56
|
+
path: placeholder_path("pb:pacticipant-branch", ["Foo", "main"])
|
57
|
+
)
|
58
|
+
.will_respond_with(
|
59
|
+
status: 204
|
60
|
+
)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "returns a success result" do
|
64
|
+
mock_index
|
65
|
+
mock_branch_delete_request
|
66
|
+
expect(subject.success).to be true
|
67
|
+
end
|
68
|
+
end
|
@@ -123,7 +123,7 @@ RSpec.describe "publishing a provider contract to PactFlow", pact: true do
|
|
123
123
|
.with(
|
124
124
|
method: :post,
|
125
125
|
path: placeholder_path("pf:publish-provider-contract", ["Bar"]),
|
126
|
-
headers: post_request_headers,
|
126
|
+
headers: post_request_headers.merge("Accept" => "application/hal+json,application/problem+json"),
|
127
127
|
body: request_body
|
128
128
|
).will_respond_with(success_response)
|
129
129
|
end
|
data/spec/support/ssl_server.rb
CHANGED
data/tasks/pact.rake
CHANGED
@@ -59,3 +59,82 @@ PactBroker::Client::PublicationTask.new(:pactflow_pact_foundation) do | task |
|
|
59
59
|
task.pact_broker_token = ENV["PACT_BROKER_TOKEN_PACT_FOUNDATION"]
|
60
60
|
task.build_url = PactBroker::Client::Git.build_url
|
61
61
|
end
|
62
|
+
PactBroker::Client::PublicationTask.new(:pactflow_auto_on_nil_commit_nil_branch) do | task |
|
63
|
+
require 'pact_broker/client/version'
|
64
|
+
# publish with auto detected commit and branch
|
65
|
+
task.auto_detect_version_properties = true
|
66
|
+
task.branch = nil
|
67
|
+
task.consumer_version = nil
|
68
|
+
task.pact_broker_base_url = ENV['PACT_BROKER_BASE_URL']
|
69
|
+
task.pact_broker_token = ENV['PACT_BROKER_TOKEN']
|
70
|
+
task.build_url = PactBroker::Client::Git.build_url
|
71
|
+
end
|
72
|
+
PactBroker::Client::PublicationTask.new(:pactflow_auto_on_user_commit_user_branch) do | task |
|
73
|
+
require 'pact_broker/client/version'
|
74
|
+
# always accept user provided commit and branch
|
75
|
+
# even when auto_detect_version_properties enabled
|
76
|
+
task.auto_detect_version_properties = true
|
77
|
+
task.branch = 'user-provided-branch'
|
78
|
+
task.consumer_version = 'user-provided-version'
|
79
|
+
task.pact_broker_base_url = ENV['PACT_BROKER_BASE_URL']
|
80
|
+
task.pact_broker_token = ENV['PACT_BROKER_TOKEN']
|
81
|
+
task.build_url = PactBroker::Client::Git.build_url
|
82
|
+
end
|
83
|
+
|
84
|
+
PactBroker::Client::PublicationTask.new(:pactflow_auto_on_user_commit_nil_branch) do | task |
|
85
|
+
require 'pact_broker/client/version'
|
86
|
+
# auto detect branch, always accept user provided commit
|
87
|
+
# even where set to auto_detect_version_properties
|
88
|
+
task.auto_detect_version_properties = true
|
89
|
+
task.branch = nil
|
90
|
+
task.consumer_version = 'user-provided-version'
|
91
|
+
task.pact_broker_base_url = ENV['PACT_BROKER_BASE_URL']
|
92
|
+
task.pact_broker_token = ENV['PACT_BROKER_TOKEN']
|
93
|
+
task.build_url = PactBroker::Client::Git.build_url
|
94
|
+
end
|
95
|
+
PactBroker::Client::PublicationTask.new(:pactflow_auto_on_nil_commit_user_branch) do | task |
|
96
|
+
require 'pact_broker/client/version'
|
97
|
+
# auto detect commit, always accept user provided branch
|
98
|
+
# even where set to auto_detect_version_properties
|
99
|
+
task.auto_detect_version_properties = true
|
100
|
+
task.branch = 'user-provided-branch'
|
101
|
+
task.consumer_version = nil
|
102
|
+
task.pact_broker_base_url = ENV['PACT_BROKER_BASE_URL']
|
103
|
+
task.pact_broker_token = ENV['PACT_BROKER_TOKEN']
|
104
|
+
task.build_url = PactBroker::Client::Git.build_url
|
105
|
+
end
|
106
|
+
|
107
|
+
PactBroker::Client::PublicationTask.new(:pactflow_auto_off_user_commit_nil_branch) do | task |
|
108
|
+
require 'pact_broker/client/version'
|
109
|
+
# accept publish without branch, but has user provided commit
|
110
|
+
# auto_detect_version_properties off
|
111
|
+
task.auto_detect_version_properties = false
|
112
|
+
task.branch = nil
|
113
|
+
task.consumer_version = 'user-provided-version'
|
114
|
+
task.pact_broker_base_url = ENV['PACT_BROKER_BASE_URL']
|
115
|
+
task.pact_broker_token = ENV['PACT_BROKER_TOKEN']
|
116
|
+
task.build_url = PactBroker::Client::Git.build_url
|
117
|
+
end
|
118
|
+
|
119
|
+
PactBroker::Client::PublicationTask.new(:pactflow_auto_off_nil_commit_nil_branch) do | task |
|
120
|
+
require 'pact_broker/client/version'
|
121
|
+
# reject publish without user provided commit
|
122
|
+
# auto_detect_version_properties off
|
123
|
+
task.auto_detect_version_properties = false
|
124
|
+
task.branch = nil
|
125
|
+
task.consumer_version = nil
|
126
|
+
task.pact_broker_base_url = ENV['PACT_BROKER_BASE_URL']
|
127
|
+
task.pact_broker_token = ENV['PACT_BROKER_TOKEN']
|
128
|
+
task.build_url = PactBroker::Client::Git.build_url
|
129
|
+
end
|
130
|
+
PactBroker::Client::PublicationTask.new(:pactflow_auto_off_empty_string_commit_nil_branch) do | task |
|
131
|
+
require 'pact_broker/client/version'
|
132
|
+
# reject publish without user provided commit
|
133
|
+
# auto_detect_version_properties off
|
134
|
+
task.auto_detect_version_properties = false
|
135
|
+
task.branch = nil
|
136
|
+
task.consumer_version = ''
|
137
|
+
task.pact_broker_base_url = ENV['PACT_BROKER_BASE_URL']
|
138
|
+
task.pact_broker_token = ENV['PACT_BROKER_TOKEN']
|
139
|
+
task.build_url = PactBroker::Client::Git.build_url
|
140
|
+
end
|