pact_broker-client 1.50.0 → 1.52.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/test.yml +1 -1
- data/CHANGELOG.md +29 -0
- data/README.md +43 -33
- data/doc/pacts/markdown/Pact Broker Client - Pact Broker.md +78 -78
- data/lib/pact_broker/client/cli/deployment_commands.rb +7 -3
- data/lib/pact_broker/client/deployments/record_deployment.rb +6 -5
- data/lib/pact_broker/client/deployments/record_undeployment.rb +20 -12
- data/lib/pact_broker/client/publish_pacts.rb +5 -6
- data/lib/pact_broker/client/publish_pacts_the_old_way.rb +4 -49
- data/lib/pact_broker/client/version.rb +1 -1
- data/pact-broker-client.gemspec +1 -1
- data/script/publish-pact.sh +1 -1
- data/script/record-deployments-and-releases.sh +12 -1
- data/spec/lib/pact_broker/client/deployments/record_deployment_spec.rb +6 -6
- data/spec/lib/pact_broker/client/deployments/record_undeployment_spec.rb +15 -7
- data/spec/lib/pact_broker/client/publish_pacts_the_old_way_spec.rb +3 -74
- data/spec/pacts/pact_broker_client-pact_broker.json +107 -104
- data/spec/service_providers/publish_pacts_spec.rb +3 -6
- data/spec/service_providers/record_deployment_spec.rb +7 -6
- data/spec/service_providers/record_undeployment_spec.rb +4 -4
- metadata +5 -7
- data/spec/service_providers/pact_broker_client_create_version_spec.rb +0 -88
@@ -25,14 +25,13 @@ module PactBroker
|
|
25
25
|
@branch = consumer_version_params[:branch]
|
26
26
|
@build_url = consumer_version_params[:build_url]
|
27
27
|
@tags = consumer_version_params[:tags] ? consumer_version_params[:tags].collect{ |tag| tag.respond_to?(:strip) ? tag.strip : tag } : []
|
28
|
-
@version_required = consumer_version_params[:version_required]
|
29
28
|
@pact_broker_client_options = pact_broker_client_options
|
30
29
|
end
|
31
30
|
|
32
31
|
def call
|
33
32
|
validate
|
34
33
|
$stdout.puts("")
|
35
|
-
result =
|
34
|
+
result = apply_tags && publish_pacts
|
36
35
|
$stdout.puts("")
|
37
36
|
if result
|
38
37
|
PactBroker::Client::CommandResult.new(true)
|
@@ -59,10 +58,6 @@ module PactBroker
|
|
59
58
|
end
|
60
59
|
end
|
61
60
|
|
62
|
-
def can_create_version_with_branch?
|
63
|
-
@can_create_version_with_branch ||= index_resource.can?('pb:pacticipant-version')
|
64
|
-
end
|
65
|
-
|
66
61
|
def merge_on_server?
|
67
62
|
pact_broker_client_options[:write] == :merge
|
68
63
|
end
|
@@ -96,49 +91,6 @@ module PactBroker
|
|
96
91
|
end
|
97
92
|
end
|
98
93
|
|
99
|
-
def create_consumer_versions
|
100
|
-
if create_versions?
|
101
|
-
consumer_names.collect do | consumer_name |
|
102
|
-
create_version(index_resource, consumer_name)
|
103
|
-
end
|
104
|
-
true
|
105
|
-
else
|
106
|
-
true
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
def create_versions?
|
111
|
-
if version_required
|
112
|
-
if can_create_version_with_branch?
|
113
|
-
true
|
114
|
-
else
|
115
|
-
raise PactBroker::Client::Error.new("This version of the Pact Broker does not support versions with branches or build URLs. Please upgrade your broker to 2.76.2 or later.")
|
116
|
-
end
|
117
|
-
elsif (branch || build_url) && can_create_version_with_branch?
|
118
|
-
true
|
119
|
-
else
|
120
|
-
false
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
def create_version(index_resource, consumer_name)
|
125
|
-
Retry.while_error do
|
126
|
-
version_resource = index_resource._link('pb:pacticipant-version').expand(version: consumer_version_number, pacticipant: consumer_name).put(version_body).assert_success!
|
127
|
-
message = if version_resource.response.status == 200
|
128
|
-
"Replaced version #{consumer_version_number} of #{consumer_name}"
|
129
|
-
else
|
130
|
-
"Created version #{consumer_version_number} of #{consumer_name}"
|
131
|
-
end
|
132
|
-
|
133
|
-
message = message + " (branch #{branch})" if branch
|
134
|
-
$stdout.puts message
|
135
|
-
if version_resource.response.status == 200
|
136
|
-
$stdout.puts ::Term::ANSIColor.yellow("Replacing the version resource is not recommended under normal circumstances and may indicate that you have not configured your Pact pipeline correctly (unless you are just re-running a build for a particular commit). For more information see https://docs.pact.io/versioning")
|
137
|
-
end
|
138
|
-
true
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
94
|
def version_body
|
143
95
|
{
|
144
96
|
branch: branch,
|
@@ -185,6 +137,9 @@ module PactBroker
|
|
185
137
|
end
|
186
138
|
|
187
139
|
def validate
|
140
|
+
if branch || build_url
|
141
|
+
$stdout.puts ::Term::ANSIColor.yellow("WARN: This version of the Pact Broker does not support versions with branches or build URLs. Please upgrade your broker to 2.86.0 or later.")
|
142
|
+
end
|
188
143
|
raise PactBroker::Client::Error.new("Please specify the consumer_version_number") unless (consumer_version_number && consumer_version_number.to_s.strip.size > 0)
|
189
144
|
raise PactBroker::Client::Error.new("Please specify the pact_broker_base_url") unless (pact_broker_base_url && pact_broker_base_url.to_s.strip.size > 0)
|
190
145
|
raise PactBroker::Client::Error.new("No pact files found") unless (pact_file_paths && pact_file_paths.any?)
|
data/pact-broker-client.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |gem|
|
|
21
21
|
gem.require_paths = ["lib"]
|
22
22
|
gem.license = 'MIT'
|
23
23
|
|
24
|
-
gem.add_runtime_dependency 'httparty', '~>0.18'
|
24
|
+
gem.add_runtime_dependency 'httparty', '~>0.18.1' # https://github.com/jnunemaker/httparty/issues/733
|
25
25
|
gem.add_runtime_dependency 'term-ansicolor', '~> 1.7'
|
26
26
|
gem.add_runtime_dependency 'table_print', '~> 1.5'
|
27
27
|
gem.add_runtime_dependency 'thor', '>= 0.20', '< 2.0'
|
data/script/publish-pact.sh
CHANGED
@@ -28,7 +28,7 @@ bundle exec bin/pact-broker create-or-update-webhook http://localhost:9393 \
|
|
28
28
|
# --contract-published
|
29
29
|
|
30
30
|
|
31
|
-
|
31
|
+
bundle exec bin/pact-broker publish spec/pacts/pact_broker_client-pact_broker.json \
|
32
32
|
--consumer-app-version 1.2.26 \
|
33
33
|
--broker-base-url http://localhost:9292 \
|
34
34
|
--broker-token localhost \
|
@@ -8,9 +8,20 @@ bundle exec bin/pact-broker record-deployment --pacticipant Foo --version 2 --en
|
|
8
8
|
bundle exec bin/pact-broker record-deployment --pacticipant Foo --version 2 --environment test --target customer-1
|
9
9
|
bundle exec bin/pact-broker record-deployment --pacticipant Foo --version 2 --environment test --target customer-1
|
10
10
|
|
11
|
+
bundle exec bin/pact-broker record-undeployment --pacticipant Foo --environment test --target customer-2
|
11
12
|
bundle exec bin/pact-broker record-undeployment --pacticipant Foo --environment test
|
12
13
|
bundle exec bin/pact-broker record-undeployment --pacticipant Foo --environment test
|
13
14
|
bundle exec bin/pact-broker record-undeployment --pacticipant Foo --environment test --target customer-1
|
14
15
|
|
15
16
|
bundle exec bin/pact-broker record-release --pacticipant Foo --version 2 --environment test
|
16
|
-
bundle exec bin/pact-broker record-support-ended --pacticipant Foo --version 2 --environment test
|
17
|
+
bundle exec bin/pact-broker record-support-ended --pacticipant Foo --version 2 --environment test
|
18
|
+
|
19
|
+
|
20
|
+
bundle exec bin/pact-broker record-deployment --pacticipant Foo --version 2 --environment test
|
21
|
+
bundle exec bin/pact-broker record-deployment --pacticipant Foo --version 2 --environment test --application-instance customer-1
|
22
|
+
bundle exec bin/pact-broker record-deployment --pacticipant Foo --version 2 --environment test --application-instance customer-1
|
23
|
+
|
24
|
+
bundle exec bin/pact-broker record-undeployment --pacticipant Foo --environment test --application-instance customer-2
|
25
|
+
bundle exec bin/pact-broker record-undeployment --pacticipant Foo --environment test
|
26
|
+
bundle exec bin/pact-broker record-undeployment --pacticipant Foo --environment test
|
27
|
+
bundle exec bin/pact-broker record-undeployment --pacticipant Foo --environment test --application-instance customer-1
|
@@ -61,14 +61,14 @@ module PactBroker
|
|
61
61
|
to_return(status: 200, body: record_deployment_body_hash.to_json , headers: {})
|
62
62
|
end
|
63
63
|
|
64
|
-
let(:
|
64
|
+
let(:application_instance) { "blue" }
|
65
65
|
|
66
66
|
let(:params) do
|
67
67
|
{
|
68
68
|
pacticipant_name: "Foo",
|
69
69
|
version_number: "1",
|
70
70
|
environment_name: "test",
|
71
|
-
|
71
|
+
application_instance: application_instance
|
72
72
|
}
|
73
73
|
end
|
74
74
|
|
@@ -186,13 +186,13 @@ module PactBroker
|
|
186
186
|
end
|
187
187
|
|
188
188
|
it "indicates the API was Pactflow" do
|
189
|
-
expect(subject.message).to include "Recorded deployment of Foo version 1 to test environment (
|
189
|
+
expect(subject.message).to include "Recorded deployment of Foo version 1 to test environment (application instance blue) in Pactflow"
|
190
190
|
end
|
191
191
|
|
192
|
-
context "when
|
193
|
-
let(:
|
192
|
+
context "when application_instance is nil" do
|
193
|
+
let(:application_instance) { nil }
|
194
194
|
|
195
|
-
it "does not include the
|
195
|
+
it "does not include the application_instance in the result message" do
|
196
196
|
expect(subject.message).to include "Recorded deployment of Foo version 1 to test environment in"
|
197
197
|
end
|
198
198
|
end
|
@@ -7,11 +7,11 @@ module PactBroker
|
|
7
7
|
let(:params) do
|
8
8
|
{
|
9
9
|
pacticipant_name: "Foo",
|
10
|
-
|
10
|
+
application_instance: application_instance,
|
11
11
|
environment_name: "test"
|
12
12
|
}
|
13
13
|
end
|
14
|
-
let(:
|
14
|
+
let(:application_instance) { "customer-1" }
|
15
15
|
let(:output) { "text" }
|
16
16
|
let(:options) { { output: output, verbose: true } }
|
17
17
|
let(:pact_broker_base_url) { "http://broker" }
|
@@ -131,7 +131,7 @@ module PactBroker
|
|
131
131
|
subject { RecordUndeployment.call(params, options, pact_broker_client_options) }
|
132
132
|
|
133
133
|
its(:success) { is_expected.to eq true }
|
134
|
-
its(:message) { is_expected.to include "Recorded undeployment of Foo version 2 from test environment (
|
134
|
+
its(:message) { is_expected.to include "Recorded undeployment of Foo version 2 from test environment (application instance customer-1) in the Pact Broker" }
|
135
135
|
|
136
136
|
context "when there is no pb:environments relation in the index" do
|
137
137
|
let(:index_body_hash) do
|
@@ -173,8 +173,8 @@ module PactBroker
|
|
173
173
|
end
|
174
174
|
|
175
175
|
context "when a target is provided and there is no deployed version with a matching target" do
|
176
|
-
let(:
|
177
|
-
let(:expected_message) { "Foo is not currently deployed to
|
176
|
+
let(:application_instance) { "wrong" }
|
177
|
+
let(:expected_message) { "Foo is not currently deployed to application instance 'wrong' in test environment. Please omit the application instance to undeploy from the anonymous instance or specify one of the following application instances to record the undeployment from: customer-1." }
|
178
178
|
|
179
179
|
its(:success) { is_expected.to be false }
|
180
180
|
its(:message) { is_expected.to include expected_message }
|
@@ -186,12 +186,20 @@ module PactBroker
|
|
186
186
|
end
|
187
187
|
end
|
188
188
|
|
189
|
+
context "when a target is provided and there is no deployed version with a matching target and all the application instances are set" do
|
190
|
+
let(:application_instance) { "wrong" }
|
191
|
+
let(:returned_target_2) { "customer-2" }
|
192
|
+
let(:expected_message) { "Foo is not currently deployed to application instance 'wrong' in test environment. Please specify one of the following application instances to record the undeployment from: customer-1, customer-2." }
|
193
|
+
|
194
|
+
its(:message) { is_expected.to include expected_message }
|
195
|
+
end
|
196
|
+
|
189
197
|
context "when a target is not provided and there is no deployed verison without a target" do
|
190
|
-
let(:
|
198
|
+
let(:application_instance) { nil }
|
191
199
|
let(:returned_target_2) { "customer-2" }
|
192
200
|
|
193
201
|
its(:success) { is_expected.to be false }
|
194
|
-
its(:message) { is_expected.to include "Please specify one of the following
|
202
|
+
its(:message) { is_expected.to include "Please specify one of the following application instances to record the undeployment from: customer-1, customer-2" }
|
195
203
|
end
|
196
204
|
|
197
205
|
context "when there are no deployed versions for the pacticipant" do
|
@@ -263,80 +263,9 @@ module PactBroker
|
|
263
263
|
context "when the broker does not support creation of a version with a branch but a branch is specified" do
|
264
264
|
let(:branch) { "main" }
|
265
265
|
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
it "raises an error" do
|
270
|
-
expect { subject.call }.to raise_error PactBroker::Client::Error
|
271
|
-
end
|
272
|
-
end
|
273
|
-
end
|
274
|
-
|
275
|
-
context "when the broker supports creation of a version with a branch" do
|
276
|
-
before do
|
277
|
-
allow(version_link).to receive(:expand).and_return(version_link)
|
278
|
-
allow(version_resource).to receive(:assert_success!).and_return(version_resource)
|
279
|
-
allow(version_resource).to receive_message_chain(:response, :status).and_return(version_creation_response_status)
|
280
|
-
end
|
281
|
-
let(:can_create_version) { true }
|
282
|
-
let(:version_link) { instance_double("PactBroker::Client::Hal::Link", put: version_resource) }
|
283
|
-
let(:version_resource) { instance_double("PactBroker::Client::Hal::Entity") }
|
284
|
-
let(:version_creation_response_status) { 201 }
|
285
|
-
|
286
|
-
before do
|
287
|
-
allow(index_resource).to receive(:_link).and_return(version_link)
|
288
|
-
end
|
289
|
-
|
290
|
-
context "when there is a branch, build_url or tags specified" do
|
291
|
-
let(:tags) { ["dev"] }
|
292
|
-
let(:branch) { ["main"] }
|
293
|
-
let(:build_url) { "build_url" }
|
294
|
-
|
295
|
-
it "creates a version with the branch, build_url and tags" do
|
296
|
-
expect(index_resource).to receive(:_link)
|
297
|
-
expect(version_link).to receive(:expand).with(pacticipant: "Consumer", version: "1.2.3")
|
298
|
-
expect(version_link).to receive(:put).with(branch: branch, buildUrl: build_url)
|
299
|
-
subject.call
|
300
|
-
end
|
301
|
-
|
302
|
-
context "when there is a branch but no tags" do
|
303
|
-
let(:tags) { [] }
|
304
|
-
|
305
|
-
it "does not set the tags, as this would overwrite the existing ones - not sure about this implementation" do
|
306
|
-
expect(version_link).to receive(:put).with(branch: branch, buildUrl: build_url)
|
307
|
-
subject.call
|
308
|
-
end
|
309
|
-
end
|
310
|
-
|
311
|
-
context "when the version response status is 201" do
|
312
|
-
it "puts a message indicating the version was created" do
|
313
|
-
expect($stdout).to receive(:puts).with(/Created/)
|
314
|
-
subject.call
|
315
|
-
end
|
316
|
-
end
|
317
|
-
|
318
|
-
context "when the version response status is 200" do
|
319
|
-
let(:version_creation_response_status) { 200 }
|
320
|
-
|
321
|
-
it "puts a message indicating the version was replaced" do
|
322
|
-
expect($stdout).to receive(:puts).with(/Replaced/)
|
323
|
-
subject.call
|
324
|
-
end
|
325
|
-
end
|
326
|
-
end
|
327
|
-
|
328
|
-
context "when there is no branch, tags or build_url specified" do
|
329
|
-
before do
|
330
|
-
allow(Retry).to receive(:while_error) { |&block| block.call }
|
331
|
-
end
|
332
|
-
let(:tags) { [] }
|
333
|
-
let(:branch) { nil }
|
334
|
-
let(:build_url) { nil }
|
335
|
-
|
336
|
-
it "does not create a version resource" do
|
337
|
-
expect(index_resource).to_not receive(:_link)
|
338
|
-
subject.call
|
339
|
-
end
|
266
|
+
it "logs a warning" do
|
267
|
+
expect($stdout).to receive(:puts).with(/WARN: This version/)
|
268
|
+
subject.call
|
340
269
|
end
|
341
270
|
end
|
342
271
|
end
|
@@ -186,110 +186,6 @@
|
|
186
186
|
}
|
187
187
|
}
|
188
188
|
},
|
189
|
-
{
|
190
|
-
"description": "a request for the index resource",
|
191
|
-
"providerState": "the pb:pacticipant-version relation exists in the index resource",
|
192
|
-
"request": {
|
193
|
-
"method": "get",
|
194
|
-
"path": "/",
|
195
|
-
"headers": {
|
196
|
-
"Accept": "application/hal+json"
|
197
|
-
}
|
198
|
-
},
|
199
|
-
"response": {
|
200
|
-
"status": 200,
|
201
|
-
"headers": {
|
202
|
-
"Content-Type": "application/hal+json;charset=utf-8"
|
203
|
-
},
|
204
|
-
"body": {
|
205
|
-
"_links": {
|
206
|
-
"pb:pacticipant-version": {
|
207
|
-
"href": "http://localhost:1234/HAL-REL-PLACEHOLDER-INDEX-PB-PACTICIPANT-VERSION-{pacticipant}-{version}"
|
208
|
-
}
|
209
|
-
}
|
210
|
-
},
|
211
|
-
"matchingRules": {
|
212
|
-
"$.body._links.pb:pacticipant-version.href": {
|
213
|
-
"match": "regex",
|
214
|
-
"regex": "http:\\/\\/.*{pacticipant}.*{version}"
|
215
|
-
}
|
216
|
-
}
|
217
|
-
}
|
218
|
-
},
|
219
|
-
{
|
220
|
-
"description": "a request to create a pacticipant version",
|
221
|
-
"providerState": "version 26f353580936ad3b9baddb17b00e84f33c69e7cb of pacticipant Foo does not exist",
|
222
|
-
"request": {
|
223
|
-
"method": "put",
|
224
|
-
"path": "/HAL-REL-PLACEHOLDER-INDEX-PB-PACTICIPANT-VERSION-Foo-26f353580936ad3b9baddb17b00e84f33c69e7cb",
|
225
|
-
"headers": {
|
226
|
-
"Content-Type": "application/json",
|
227
|
-
"Accept": "application/hal+json"
|
228
|
-
},
|
229
|
-
"body": {
|
230
|
-
"branch": "main",
|
231
|
-
"buildUrl": "http://my-ci/builds/1"
|
232
|
-
}
|
233
|
-
},
|
234
|
-
"response": {
|
235
|
-
"status": 201,
|
236
|
-
"headers": {
|
237
|
-
"Content-Type": "application/hal+json;charset=utf-8"
|
238
|
-
},
|
239
|
-
"body": {
|
240
|
-
"number": "26f353580936ad3b9baddb17b00e84f33c69e7cb",
|
241
|
-
"buildUrl": "http://my-ci/builds/1",
|
242
|
-
"_links": {
|
243
|
-
"self": {
|
244
|
-
"href": "http://localhost:1234/some-url"
|
245
|
-
}
|
246
|
-
}
|
247
|
-
},
|
248
|
-
"matchingRules": {
|
249
|
-
"$.body._links.self.href": {
|
250
|
-
"match": "regex",
|
251
|
-
"regex": "http:\\/\\/.*"
|
252
|
-
}
|
253
|
-
}
|
254
|
-
}
|
255
|
-
},
|
256
|
-
{
|
257
|
-
"description": "a request to create a pacticipant version",
|
258
|
-
"providerState": "version 26f353580936ad3b9baddb17b00e84f33c69e7cb of pacticipant Foo does exist",
|
259
|
-
"request": {
|
260
|
-
"method": "put",
|
261
|
-
"path": "/HAL-REL-PLACEHOLDER-INDEX-PB-PACTICIPANT-VERSION-Foo-26f353580936ad3b9baddb17b00e84f33c69e7cb",
|
262
|
-
"headers": {
|
263
|
-
"Content-Type": "application/json",
|
264
|
-
"Accept": "application/hal+json"
|
265
|
-
},
|
266
|
-
"body": {
|
267
|
-
"branch": "main",
|
268
|
-
"buildUrl": "http://my-ci/builds/1"
|
269
|
-
}
|
270
|
-
},
|
271
|
-
"response": {
|
272
|
-
"status": 200,
|
273
|
-
"headers": {
|
274
|
-
"Content-Type": "application/hal+json;charset=utf-8"
|
275
|
-
},
|
276
|
-
"body": {
|
277
|
-
"number": "26f353580936ad3b9baddb17b00e84f33c69e7cb",
|
278
|
-
"buildUrl": "http://my-ci/builds/1",
|
279
|
-
"_links": {
|
280
|
-
"self": {
|
281
|
-
"href": "http://localhost:1234/some-url"
|
282
|
-
}
|
283
|
-
}
|
284
|
-
},
|
285
|
-
"matchingRules": {
|
286
|
-
"$.body._links.self.href": {
|
287
|
-
"match": "regex",
|
288
|
-
"regex": "http:\\/\\/.*"
|
289
|
-
}
|
290
|
-
}
|
291
|
-
}
|
292
|
-
},
|
293
189
|
{
|
294
190
|
"description": "a request to determine if Bar can be deployed with all Foo tagged prod, ignoring the verification for Foo version 3.4.5",
|
295
191
|
"providerState": "provider Bar version 4.5.6 has a successful verification for Foo version 1.2.3 tagged prod and a failed verification for version 3.4.5 tagged prod",
|
@@ -1636,6 +1532,112 @@
|
|
1636
1532
|
}
|
1637
1533
|
}
|
1638
1534
|
},
|
1535
|
+
{
|
1536
|
+
"description": "a request for the index resource",
|
1537
|
+
"providerState": "the pb:publish-contracts relations exists in the index resource",
|
1538
|
+
"request": {
|
1539
|
+
"method": "GET",
|
1540
|
+
"path": "/",
|
1541
|
+
"headers": {
|
1542
|
+
"Accept": "application/hal+json"
|
1543
|
+
}
|
1544
|
+
},
|
1545
|
+
"response": {
|
1546
|
+
"status": 200,
|
1547
|
+
"headers": {
|
1548
|
+
"Content-Type": "application/hal+json;charset=utf-8"
|
1549
|
+
},
|
1550
|
+
"body": {
|
1551
|
+
"_links": {
|
1552
|
+
"pb:publish-contracts": {
|
1553
|
+
"href": "http://localhost:1234/HAL-REL-PLACEHOLDER-PB-PUBLISH-CONTRACTS"
|
1554
|
+
}
|
1555
|
+
}
|
1556
|
+
},
|
1557
|
+
"matchingRules": {
|
1558
|
+
"$.body._links.pb:publish-contracts.href": {
|
1559
|
+
"match": "regex",
|
1560
|
+
"regex": "http:\\/\\/.*"
|
1561
|
+
}
|
1562
|
+
}
|
1563
|
+
}
|
1564
|
+
},
|
1565
|
+
{
|
1566
|
+
"description": "a request to publish contracts",
|
1567
|
+
"request": {
|
1568
|
+
"method": "POST",
|
1569
|
+
"path": "/HAL-REL-PLACEHOLDER-PB-PUBLISH-CONTRACTS",
|
1570
|
+
"headers": {
|
1571
|
+
"Content-Type": "application/json",
|
1572
|
+
"Accept": "application/hal+json"
|
1573
|
+
},
|
1574
|
+
"body": {
|
1575
|
+
"pacticipantName": "Foo",
|
1576
|
+
"pacticipantVersionNumber": "5556b8149bf8bac76bc30f50a8a2dd4c22c85f30",
|
1577
|
+
"branch": "main",
|
1578
|
+
"tags": [
|
1579
|
+
"dev"
|
1580
|
+
],
|
1581
|
+
"buildUrl": "http://build",
|
1582
|
+
"contracts": [
|
1583
|
+
{
|
1584
|
+
"consumerName": "Foo",
|
1585
|
+
"providerName": "Bar",
|
1586
|
+
"specification": "pact",
|
1587
|
+
"contentType": "application/json",
|
1588
|
+
"content": "eyJjb25zdW1lciI6eyJuYW1lIjoiRm9vIn0sInByb3ZpZGVyIjp7Im5hbWUiOiJCYXIifSwiaW50ZXJhY3Rpb25zIjpbeyJkZXNjcmlwdGlvbiI6ImFuIGV4YW1wbGUgcmVxdWVzdCIsInByb3ZpZGVyU3RhdGUiOiJhIHByb3ZpZGVyIHN0YXRlIiwicmVxdWVzdCI6eyJtZXRob2QiOiJHRVQiLCJwYXRoIjoiLyIsImhlYWRlcnMiOnt9fSwicmVzcG9uc2UiOnsic3RhdHVzIjoyMDAsImhlYWRlcnMiOnsiQ29udGVudC1UeXBlIjoiYXBwbGljYXRpb24vaGFsK2pzb24ifX19XSwibWV0YWRhdGEiOnsicGFjdFNwZWNpZmljYXRpb24iOnsidmVyc2lvbiI6IjIuMC4wIn19fQ==",
|
1589
|
+
"onConflict": "merge"
|
1590
|
+
}
|
1591
|
+
]
|
1592
|
+
}
|
1593
|
+
},
|
1594
|
+
"response": {
|
1595
|
+
"status": 200,
|
1596
|
+
"headers": {
|
1597
|
+
"Content-Type": "application/hal+json;charset=utf-8"
|
1598
|
+
},
|
1599
|
+
"body": {
|
1600
|
+
"_embedded": {
|
1601
|
+
"pacticipant": {
|
1602
|
+
"name": "Foo"
|
1603
|
+
},
|
1604
|
+
"version": {
|
1605
|
+
"number": "5556b8149bf8bac76bc30f50a8a2dd4c22c85f30",
|
1606
|
+
"buildUrl": "http://build"
|
1607
|
+
}
|
1608
|
+
},
|
1609
|
+
"logs": [
|
1610
|
+
{
|
1611
|
+
"level": "info",
|
1612
|
+
"message": "some message"
|
1613
|
+
}
|
1614
|
+
],
|
1615
|
+
"_links": {
|
1616
|
+
"pb:pacticipant-version-tags": [
|
1617
|
+
{
|
1618
|
+
"name": "dev"
|
1619
|
+
}
|
1620
|
+
],
|
1621
|
+
"pb:contracts": [
|
1622
|
+
{
|
1623
|
+
"href": "http://some-pact"
|
1624
|
+
}
|
1625
|
+
]
|
1626
|
+
}
|
1627
|
+
},
|
1628
|
+
"matchingRules": {
|
1629
|
+
"$.body.logs": {
|
1630
|
+
"min": 1
|
1631
|
+
},
|
1632
|
+
"$.body.logs[*].*": {
|
1633
|
+
"match": "type"
|
1634
|
+
},
|
1635
|
+
"$.body._links.pb:contracts[0].href": {
|
1636
|
+
"match": "type"
|
1637
|
+
}
|
1638
|
+
}
|
1639
|
+
}
|
1640
|
+
},
|
1639
1641
|
{
|
1640
1642
|
"description": "a request for the index resource",
|
1641
1643
|
"providerState": "the pb:pacticipant-version and pb:environments relations exist in the index resource",
|
@@ -1717,6 +1719,7 @@
|
|
1717
1719
|
"Accept": "application/hal+json"
|
1718
1720
|
},
|
1719
1721
|
"body": {
|
1722
|
+
"applicationInstance": "blue",
|
1720
1723
|
"target": "blue"
|
1721
1724
|
}
|
1722
1725
|
},
|
@@ -1,9 +1,7 @@
|
|
1
1
|
require 'pact_broker/client/publish_pacts'
|
2
2
|
require 'service_providers/pact_helper'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
RSpec.describe "publishing contracts", pact: true, skip: !publish_contracts_feature_on do
|
4
|
+
RSpec.describe "publishing contracts", pact: true do
|
7
5
|
before do
|
8
6
|
allow_any_instance_of(PactBroker::Client::Hal::HttpClient).to receive(:sleep)
|
9
7
|
allow_any_instance_of(PactBroker::Client::Hal::HttpClient).to receive(:default_max_tries).and_return(1)
|
@@ -27,7 +25,7 @@ RSpec.describe "publishing contracts", pact: true, skip: !publish_contracts_feat
|
|
27
25
|
end
|
28
26
|
let(:pact_file_path_1) { "spec/fixtures/foo-bar.json" }
|
29
27
|
let(:pact_file_paths) { [pact_file_path_1] }
|
30
|
-
let(:options) { {} }
|
28
|
+
let(:options) { { merge: true } }
|
31
29
|
let(:pact_broker_client_options) { {} }
|
32
30
|
let(:expected_content) { Base64.strict_encode64(JSON.parse(File.read(pact_file_path_1)).to_json) }
|
33
31
|
let(:request_body) do
|
@@ -44,8 +42,7 @@ RSpec.describe "publishing contracts", pact: true, skip: !publish_contracts_feat
|
|
44
42
|
specification: "pact",
|
45
43
|
contentType: "application/json",
|
46
44
|
content: expected_content,
|
47
|
-
|
48
|
-
onConflict: "overwrite"
|
45
|
+
onConflict: "merge"
|
49
46
|
}
|
50
47
|
]
|
51
48
|
}
|
@@ -9,13 +9,13 @@ RSpec.describe "recording a deployment", pact: true do
|
|
9
9
|
let(:version_number) { "5556b8149bf8bac76bc30f50a8a2dd4c22c85f30" }
|
10
10
|
let(:environment_name) { "test" }
|
11
11
|
let(:output) { "text" }
|
12
|
-
let(:
|
12
|
+
let(:application_instance) { "blue" }
|
13
13
|
let(:params) do
|
14
14
|
{
|
15
15
|
pacticipant_name: pacticipant_name,
|
16
16
|
version_number: version_number,
|
17
17
|
environment_name: environment_name,
|
18
|
-
|
18
|
+
application_instance: application_instance
|
19
19
|
}
|
20
20
|
end
|
21
21
|
let(:options) do
|
@@ -139,14 +139,15 @@ RSpec.describe "recording a deployment", pact: true do
|
|
139
139
|
path: "/HAL-REL-PLACEHOLDER-PB-RECORD-DEPLOYMENT-FOO-5556B8149BF8BAC76BC30F50A8A2DD4C22C85F30-TEST",
|
140
140
|
headers: post_request_headers,
|
141
141
|
body: {
|
142
|
-
|
142
|
+
applicationInstance: application_instance,
|
143
|
+
target: application_instance
|
143
144
|
}
|
144
145
|
)
|
145
146
|
.will_respond_with(
|
146
147
|
status: 201,
|
147
148
|
headers: pact_broker_response_headers,
|
148
149
|
body: {
|
149
|
-
target:
|
150
|
+
target: application_instance
|
150
151
|
}
|
151
152
|
)
|
152
153
|
end
|
@@ -160,14 +161,14 @@ RSpec.describe "recording a deployment", pact: true do
|
|
160
161
|
|
161
162
|
it "returns a success message" do
|
162
163
|
expect(subject.success).to be true
|
163
|
-
expect(subject.message).to include "Recorded deployment of Foo version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 to test environment (
|
164
|
+
expect(subject.message).to include "Recorded deployment of Foo version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 to test environment (application instance blue) in the Pact Broker."
|
164
165
|
end
|
165
166
|
|
166
167
|
context "when the output is json" do
|
167
168
|
let(:output) { "json" }
|
168
169
|
|
169
170
|
it "returns the JSON payload" do
|
170
|
-
expect(JSON.parse(subject.message)).to eq "target" =>
|
171
|
+
expect(JSON.parse(subject.message)).to eq "target" => application_instance
|
171
172
|
end
|
172
173
|
end
|
173
174
|
end
|
@@ -8,12 +8,12 @@ RSpec.describe "recording an undeployment", pact: true do
|
|
8
8
|
let(:pacticipant_name) { "Foo" }
|
9
9
|
let(:environment_name) { "test" }
|
10
10
|
let(:output) { "text" }
|
11
|
-
let(:
|
11
|
+
let(:application_instance) { "customer-1" }
|
12
12
|
let(:params) do
|
13
13
|
{
|
14
14
|
pacticipant_name: pacticipant_name,
|
15
15
|
environment_name: environment_name,
|
16
|
-
|
16
|
+
application_instance: application_instance
|
17
17
|
}
|
18
18
|
end
|
19
19
|
let(:options) do
|
@@ -100,7 +100,7 @@ RSpec.describe "recording an undeployment", pact: true do
|
|
100
100
|
_embedded: {
|
101
101
|
deployedVersions: [
|
102
102
|
{
|
103
|
-
target:
|
103
|
+
target: application_instance,
|
104
104
|
_links: {
|
105
105
|
self: {
|
106
106
|
href: Pact.term(pact_broker.mock_service_base_url + deployed_version_placeholder_path, /^http/)
|
@@ -150,7 +150,7 @@ RSpec.describe "recording an undeployment", pact: true do
|
|
150
150
|
|
151
151
|
it "returns a success message" do
|
152
152
|
expect(subject.success).to be true
|
153
|
-
expect(subject.message).to include "Recorded undeployment of Foo version 2 from test environment (
|
153
|
+
expect(subject.message).to include "Recorded undeployment of Foo version 2 from test environment (application instance customer-1) in the Pact Broker"
|
154
154
|
end
|
155
155
|
|
156
156
|
context "when the output is json" do
|