pact_broker-client 1.35.0 → 1.36.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/doc/pacts/markdown/Pact Broker Client - Pact Broker.md +103 -0
- data/lib/pact_broker/client/cli/broker.rb +28 -4
- data/lib/pact_broker/client/cli/can_i_deploy_long_desc.txt +18 -9
- data/lib/pact_broker/client/git.rb +40 -22
- data/lib/pact_broker/client/matrix.rb +2 -1
- data/lib/pact_broker/client/publish_pacts.rb +84 -14
- data/lib/pact_broker/client/tasks/publication_task.rb +35 -6
- data/lib/pact_broker/client/version.rb +1 -1
- data/script/publish-pact.sh +7 -1
- data/spec/lib/pact_broker/client/cli/broker_can_i_deploy_spec.rb +13 -2
- data/spec/lib/pact_broker/client/cli/broker_publish_spec.rb +108 -12
- data/spec/lib/pact_broker/client/git_spec.rb +39 -2
- data/spec/lib/pact_broker/client/publish_pacts_spec.rb +99 -6
- data/spec/lib/pact_broker/client/tasks/publication_task_spec.rb +88 -10
- data/spec/pacts/pact_broker_client-pact_broker.json +106 -0
- data/spec/service_providers/pact_broker_client_create_version_spec.rb +89 -0
- data/spec/service_providers/pact_broker_client_matrix_spec.rb +4 -0
- data/spec/service_providers/pact_broker_client_versions_spec.rb +1 -2
- data/tasks/pact.rake +2 -0
- metadata +5 -3
@@ -3,7 +3,6 @@ require 'pact_broker/client/tasks/publication_task'
|
|
3
3
|
require 'pact_broker/client/publish_pacts'
|
4
4
|
|
5
5
|
module PactBroker::Client
|
6
|
-
|
7
6
|
describe PublicationTask do
|
8
7
|
|
9
8
|
before do
|
@@ -22,7 +21,6 @@ module PactBroker::Client
|
|
22
21
|
let(:pattern) { "spec/pacts/*.json" }
|
23
22
|
|
24
23
|
describe "default task" do
|
25
|
-
|
26
24
|
before :all do
|
27
25
|
PactBroker::Client::PublicationTask.new do | task |
|
28
26
|
task.consumer_version = '1.2.3'
|
@@ -31,7 +29,7 @@ module PactBroker::Client
|
|
31
29
|
|
32
30
|
context "when pacts are succesfully published" do
|
33
31
|
it "invokes PublishPacts with the default values" do
|
34
|
-
expect(PactBroker::Client::PublishPacts).to receive(:new).with('http://pact-broker', pact_file_list, '1.2.3', [], {}).and_return(publish_pacts)
|
32
|
+
expect(PactBroker::Client::PublishPacts).to receive(:new).with('http://pact-broker', pact_file_list, { number: '1.2.3', branch: "foo", tags: [], version_required: false}, {}).and_return(publish_pacts)
|
35
33
|
expect(publish_pacts).to receive(:call).and_return(true)
|
36
34
|
Rake::Task['pact:publish'].execute
|
37
35
|
end
|
@@ -54,7 +52,7 @@ module PactBroker::Client
|
|
54
52
|
end
|
55
53
|
|
56
54
|
it "invokes PublishPacts with the write method set" do
|
57
|
-
expect(PactBroker::Client::PublishPacts).to receive(:new).with('http://pact-broker', pact_file_list,
|
55
|
+
expect(PactBroker::Client::PublishPacts).to receive(:new).with('http://pact-broker', pact_file_list, { number: "1.2.3", branch: "foo", tags: [], version_required: false }, {write: :merge}).and_return(publish_pacts)
|
58
56
|
expect(publish_pacts).to receive(:call).and_return(true)
|
59
57
|
Rake::Task['pact:publish:merge'].execute
|
60
58
|
end
|
@@ -65,17 +63,98 @@ module PactBroker::Client
|
|
65
63
|
PactBroker::Client::PublicationTask.new(:git_branch) do | task |
|
66
64
|
task.consumer_version = '1.2.3'
|
67
65
|
task.tag_with_git_branch = true
|
66
|
+
task.auto_detect_version_properties = false
|
68
67
|
task.tags = ['bar']
|
69
68
|
end
|
70
69
|
end
|
71
70
|
|
72
|
-
it "
|
73
|
-
expect(PactBroker::Client::
|
71
|
+
it "gets the git branch name" do
|
72
|
+
expect(PactBroker::Client::Git).to receive(:branch).with(raise_error: true)
|
73
|
+
Rake::Task['pact:publish:git_branch'].execute
|
74
|
+
end
|
74
75
|
|
76
|
+
it "invokes PublishPacts with the git branch name as a tag" do
|
77
|
+
expect(PactBroker::Client::PublishPacts).to receive(:new).with(anything, anything, hash_including(tags: ['bar', 'foo']), anything).and_return(publish_pacts)
|
75
78
|
Rake::Task['pact:publish:git_branch'].execute
|
76
79
|
end
|
77
80
|
end
|
78
81
|
|
82
|
+
context "when auto_detect_version_properties is explicitly set to true" do
|
83
|
+
before :all do
|
84
|
+
PactBroker::Client::PublicationTask.new(:git_branch_auto_detect_true) do | task |
|
85
|
+
task.consumer_version = '1.2.3'
|
86
|
+
task.auto_detect_version_properties = true
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
it "gets the git branch name" do
|
91
|
+
expect(PactBroker::Client::Git).to receive(:branch).with(raise_error: true)
|
92
|
+
Rake::Task['pact:publish:git_branch_auto_detect_true'].execute
|
93
|
+
end
|
94
|
+
|
95
|
+
it "invokes PublishPacts with the branch name" do
|
96
|
+
expect(PactBroker::Client::PublishPacts).to receive(:new).with(anything, anything, hash_including(branch: "foo"), anything).and_return(publish_pacts)
|
97
|
+
Rake::Task['pact:publish:git_branch_auto_detect_true'].execute
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context "when auto_detect_version_properties is explicitly set to true and the branch is specified" do
|
102
|
+
before :all do
|
103
|
+
PactBroker::Client::PublicationTask.new(:git_branch_auto_detect_true_with_branch) do | task |
|
104
|
+
task.consumer_version = '1.2.3'
|
105
|
+
task.auto_detect_version_properties = true
|
106
|
+
task.branch = "main"
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
it "does not get the branch name" do
|
111
|
+
expect(PactBroker::Client::Git).to_not receive(:branch)
|
112
|
+
Rake::Task['pact:publish:git_branch_auto_detect_true_with_branch'].execute
|
113
|
+
end
|
114
|
+
|
115
|
+
it "invokes PublishPacts with the specified branch name" do
|
116
|
+
expect(PactBroker::Client::PublishPacts).to receive(:new).with(anything, anything, hash_including(branch: "main"), anything).and_return(publish_pacts)
|
117
|
+
Rake::Task['pact:publish:git_branch_auto_detect_true_with_branch'].execute
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
context "when auto_detect_version_properties is explicitly set to false" do
|
122
|
+
before :all do
|
123
|
+
PactBroker::Client::PublicationTask.new(:git_branch_auto_detect_false) do | task |
|
124
|
+
task.consumer_version = '1.2.3'
|
125
|
+
task.auto_detect_version_properties = false
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
it "does not get the git branch name" do
|
130
|
+
expect(PactBroker::Client::Git).to_not receive(:branch)
|
131
|
+
Rake::Task['pact:publish:git_branch_auto_detect_false'].execute
|
132
|
+
end
|
133
|
+
|
134
|
+
it "invokes PublishPacts without the branch name" do
|
135
|
+
expect(PactBroker::Client::PublishPacts).to receive(:new).with(anything, anything, hash_not_including(branch: "foo"), anything).and_return(publish_pacts)
|
136
|
+
Rake::Task['pact:publish:git_branch_auto_detect_false'].execute
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
context "when auto_detect_version_properties is left as its default" do
|
141
|
+
before :all do
|
142
|
+
PactBroker::Client::PublicationTask.new(:git_branch_auto_detect_default) do | task |
|
143
|
+
task.consumer_version = '1.2.3'
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
it "gets the git branch name" do
|
148
|
+
expect(PactBroker::Client::Git).to receive(:branch).with(raise_error: false)
|
149
|
+
Rake::Task['pact:publish:git_branch_auto_detect_default'].execute
|
150
|
+
end
|
151
|
+
|
152
|
+
it "invokes PublishPacts with the branch name" do
|
153
|
+
expect(PactBroker::Client::PublishPacts).to receive(:new).with(anything, anything, hash_including(branch: "foo"), anything).and_return(publish_pacts)
|
154
|
+
Rake::Task['pact:publish:git_branch_auto_detect_default'].execute
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
79
158
|
describe "custom task" do
|
80
159
|
|
81
160
|
before :all do
|
@@ -98,10 +177,9 @@ module PactBroker::Client
|
|
98
177
|
|
99
178
|
it "invokes PublishPacts with the customised values" do
|
100
179
|
expect(PactBroker::Client::PublishPacts).to receive(:new).with(
|
101
|
-
@pact_broker_base_url,
|
102
|
-
pact_file_list,
|
103
|
-
|
104
|
-
[@tag],
|
180
|
+
@pact_broker_base_url,
|
181
|
+
pact_file_list,
|
182
|
+
{ number: "1.2.3", tags: [@tag], branch: "foo", version_required: false},
|
105
183
|
{ basic_auth: @pact_broker_basic_auth, token: @pact_broker_token }
|
106
184
|
)
|
107
185
|
expect(publish_pacts).to receive(:call).and_return(true)
|
@@ -186,6 +186,112 @@
|
|
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
|
+
"branch": "main",
|
242
|
+
"buildUrl": "http://my-ci/builds/1",
|
243
|
+
"_links": {
|
244
|
+
"self": {
|
245
|
+
"href": "http://localhost:1234/some-url"
|
246
|
+
}
|
247
|
+
}
|
248
|
+
},
|
249
|
+
"matchingRules": {
|
250
|
+
"$.body._links.self.href": {
|
251
|
+
"match": "regex",
|
252
|
+
"regex": "http:\\/\\/.*"
|
253
|
+
}
|
254
|
+
}
|
255
|
+
}
|
256
|
+
},
|
257
|
+
{
|
258
|
+
"description": "a request to create a pacticipant version",
|
259
|
+
"providerState": "version 26f353580936ad3b9baddb17b00e84f33c69e7cb of pacticipant Foo does exist",
|
260
|
+
"request": {
|
261
|
+
"method": "put",
|
262
|
+
"path": "/HAL-REL-PLACEHOLDER-INDEX-PB-PACTICIPANT-VERSION-Foo-26f353580936ad3b9baddb17b00e84f33c69e7cb",
|
263
|
+
"headers": {
|
264
|
+
"Content-Type": "application/json",
|
265
|
+
"Accept": "application/hal+json"
|
266
|
+
},
|
267
|
+
"body": {
|
268
|
+
"branch": "main",
|
269
|
+
"buildUrl": "http://my-ci/builds/1"
|
270
|
+
}
|
271
|
+
},
|
272
|
+
"response": {
|
273
|
+
"status": 200,
|
274
|
+
"headers": {
|
275
|
+
"Content-Type": "application/hal+json;charset=utf-8"
|
276
|
+
},
|
277
|
+
"body": {
|
278
|
+
"number": "26f353580936ad3b9baddb17b00e84f33c69e7cb",
|
279
|
+
"branch": "main",
|
280
|
+
"buildUrl": "http://my-ci/builds/1",
|
281
|
+
"_links": {
|
282
|
+
"self": {
|
283
|
+
"href": "http://localhost:1234/some-url"
|
284
|
+
}
|
285
|
+
}
|
286
|
+
},
|
287
|
+
"matchingRules": {
|
288
|
+
"$.body._links.self.href": {
|
289
|
+
"match": "regex",
|
290
|
+
"regex": "http:\\/\\/.*"
|
291
|
+
}
|
292
|
+
}
|
293
|
+
}
|
294
|
+
},
|
189
295
|
{
|
190
296
|
"description": "a request for the compatibility matrix for Foo version 1.2.3 and Bar version 4.5.6",
|
191
297
|
"providerState": "the pact for Foo version 1.2.3 has been verified by Bar version 4.5.6",
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require_relative 'pact_helper'
|
2
|
+
require 'pact_broker/client'
|
3
|
+
require 'pact_broker/client/publish_pacts'
|
4
|
+
|
5
|
+
describe PactBroker::Client::Versions, pact: true do
|
6
|
+
|
7
|
+
include_context "pact broker"
|
8
|
+
|
9
|
+
|
10
|
+
describe "creating a pacticipant version" do
|
11
|
+
before do
|
12
|
+
allow(publish_pacts).to receive(:consumer_names).and_return(["Foo"])
|
13
|
+
allow($stdout).to receive(:puts)
|
14
|
+
end
|
15
|
+
let(:version_path) { "/HAL-REL-PLACEHOLDER-INDEX-PB-PACTICIPANT-VERSION-{pacticipant}-{version}" }
|
16
|
+
let(:version_url) { pact_broker.mock_service_base_url + version_path }
|
17
|
+
let(:number) { "26f353580936ad3b9baddb17b00e84f33c69e7cb" }
|
18
|
+
let(:branch) { "main" }
|
19
|
+
let(:build_url) { "http://my-ci/builds/1" }
|
20
|
+
let(:consumer_version_params) { { number: number, branch: branch, build_url: build_url } }
|
21
|
+
let(:publish_pacts) { PactBroker::Client::PublishPacts.new(pact_broker.mock_service_base_url, ["some-pact.json"], consumer_version_params, {}) }
|
22
|
+
let(:provider_state) { "version #{number} of pacticipant Foo does not exist" }
|
23
|
+
let(:expected_response_status) { 201 }
|
24
|
+
|
25
|
+
subject { publish_pacts.send(:create_consumer_versions) }
|
26
|
+
|
27
|
+
before do
|
28
|
+
pact_broker
|
29
|
+
.given("the pb:pacticipant-version relation exists in the index resource")
|
30
|
+
.upon_receiving("a request for the index resource")
|
31
|
+
.with(
|
32
|
+
method: :get,
|
33
|
+
path: '/',
|
34
|
+
headers: get_request_headers).
|
35
|
+
will_respond_with(
|
36
|
+
status: 200,
|
37
|
+
headers: pact_broker_response_headers,
|
38
|
+
body: {
|
39
|
+
_links: {
|
40
|
+
:'pb:pacticipant-version' => {
|
41
|
+
href: Pact.term(version_url, /http:\/\/.*{pacticipant}.*{version}/)
|
42
|
+
}
|
43
|
+
}
|
44
|
+
}
|
45
|
+
)
|
46
|
+
|
47
|
+
pact_broker
|
48
|
+
.given(provider_state)
|
49
|
+
.upon_receiving("a request to create a pacticipant version")
|
50
|
+
.with(
|
51
|
+
method: :put,
|
52
|
+
path: "/HAL-REL-PLACEHOLDER-INDEX-PB-PACTICIPANT-VERSION-Foo-#{number}",
|
53
|
+
headers: put_request_headers,
|
54
|
+
body: {
|
55
|
+
branch: branch,
|
56
|
+
buildUrl: build_url
|
57
|
+
}).
|
58
|
+
will_respond_with(
|
59
|
+
status: expected_response_status,
|
60
|
+
headers: pact_broker_response_headers,
|
61
|
+
body: {
|
62
|
+
number: number,
|
63
|
+
branch: branch,
|
64
|
+
buildUrl: build_url,
|
65
|
+
_links: {
|
66
|
+
self: {
|
67
|
+
href: Pact.term('http://localhost:1234/some-url', %r{http://.*})
|
68
|
+
}
|
69
|
+
}
|
70
|
+
}
|
71
|
+
)
|
72
|
+
end
|
73
|
+
|
74
|
+
context "when the version does not already exist" do
|
75
|
+
it "returns true" do
|
76
|
+
expect(subject).to be true
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context "when the version does exist" do
|
81
|
+
let(:provider_state) { "version #{number} of pacticipant Foo does exist" }
|
82
|
+
let(:expected_response_status) { 200 }
|
83
|
+
|
84
|
+
it "returns true" do
|
85
|
+
expect(subject).to be true
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
data/tasks/pact.rake
CHANGED
@@ -5,6 +5,8 @@ PactBroker::Client::PublicationTask.new(:localhost) do | task |
|
|
5
5
|
task.tag = `git rev-parse --abbrev-ref HEAD`.strip
|
6
6
|
task.consumer_version = PactBroker::Client::VERSION
|
7
7
|
task.pact_broker_base_url = "http://localhost:9292"
|
8
|
+
task.build_url = "http://ci"
|
9
|
+
# task.branch = "main"
|
8
10
|
end
|
9
11
|
|
10
12
|
PactBroker::Client::PublicationTask.new(:remote) do | task |
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pact_broker-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.36.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Beth Skurrie
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -287,6 +287,7 @@ files:
|
|
287
287
|
- spec/pacts/pact_broker_client-pact_broker.json
|
288
288
|
- spec/service_providers/extra_goodies_spec.rb
|
289
289
|
- spec/service_providers/list_latest_pact_versions_spec.rb.bak
|
290
|
+
- spec/service_providers/pact_broker_client_create_version_spec.rb
|
290
291
|
- spec/service_providers/pact_broker_client_matrix_spec.rb
|
291
292
|
- spec/service_providers/pact_broker_client_pacticipant_version_spec.rb
|
292
293
|
- spec/service_providers/pact_broker_client_publish_spec.rb
|
@@ -330,7 +331,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
330
331
|
- !ruby/object:Gem::Version
|
331
332
|
version: '0'
|
332
333
|
requirements: []
|
333
|
-
rubygems_version: 3.2.
|
334
|
+
rubygems_version: 3.2.11
|
334
335
|
signing_key:
|
335
336
|
specification_version: 4
|
336
337
|
summary: See description
|
@@ -367,6 +368,7 @@ test_files:
|
|
367
368
|
- spec/pacts/pact_broker_client-pact_broker.json
|
368
369
|
- spec/service_providers/extra_goodies_spec.rb
|
369
370
|
- spec/service_providers/list_latest_pact_versions_spec.rb.bak
|
371
|
+
- spec/service_providers/pact_broker_client_create_version_spec.rb
|
370
372
|
- spec/service_providers/pact_broker_client_matrix_spec.rb
|
371
373
|
- spec/service_providers/pact_broker_client_pacticipant_version_spec.rb
|
372
374
|
- spec/service_providers/pact_broker_client_publish_spec.rb
|