pact_broker-client 0.0.1
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.
- data/.gitignore +25 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +76 -0
- data/README.md +94 -0
- data/Rakefile +33 -0
- data/ci.sh +10 -0
- data/lib/pact_broker/client/base_client.rb +76 -0
- data/lib/pact_broker/client/pact_broker_client.rb +31 -0
- data/lib/pact_broker/client/pacticipants.rb +34 -0
- data/lib/pact_broker/client/pacts.rb +45 -0
- data/lib/pact_broker/client/publish_pacts.rb +44 -0
- data/lib/pact_broker/client/tasks/publication_task.rb +46 -0
- data/lib/pact_broker/client/tasks.rb +1 -0
- data/lib/pact_broker/client/version.rb +5 -0
- data/lib/pact_broker/client/versions.rb +38 -0
- data/lib/pact_broker/client.rb +2 -0
- data/lib/pact_broker_client.rb +2 -0
- data/pact-broker-client.gemspec +32 -0
- data/spec/lib/pact_broker/client/pact_broker_client_spec.rb +20 -0
- data/spec/lib/pact_broker/client/publish_pacts_spec.rb +92 -0
- data/spec/lib/pact_broker/client/tasks/publication_task_spec.rb +72 -0
- data/spec/pacts/pact_broker_client-pact_broker.json +365 -0
- data/spec/service_providers/pact_broker_client_spec.rb +363 -0
- data/spec/service_providers/pact_helper.rb +14 -0
- data/spec/spec_helper.rb +5 -0
- metadata +213 -0
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fakefs/safe'
|
3
|
+
require 'pact_broker/client/publish_pacts'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module PactBroker
|
7
|
+
module Client
|
8
|
+
describe PublishPacts do
|
9
|
+
|
10
|
+
before do
|
11
|
+
FakeFS.activate!
|
12
|
+
pacts_client.stub(:publish)
|
13
|
+
PactBroker::Client::PactBrokerClient.stub(:new).with(base_url: pact_broker_base_url).and_return(pact_broker_client)
|
14
|
+
end
|
15
|
+
|
16
|
+
after do
|
17
|
+
FakeFS.deactivate!
|
18
|
+
end
|
19
|
+
|
20
|
+
let(:pact_broker_client) { double("PactBroker::Client")}
|
21
|
+
let(:pact_files) { ['spec/pacts/consumer-provider.json']}
|
22
|
+
let(:consumer_version) { "1.2.3" }
|
23
|
+
let(:pact_hash) { {consumer: {name: 'Consumer'}, provider: {name: 'Provider'} } }
|
24
|
+
let(:pacts_client) { instance_double("PactBroker::ClientSupport::Pacts")}
|
25
|
+
let(:pact_broker_base_url) { 'http://some-host'}
|
26
|
+
|
27
|
+
subject { PublishPacts.new(pact_broker_base_url, pact_files, consumer_version) }
|
28
|
+
|
29
|
+
before do
|
30
|
+
FileUtils.mkdir_p "spec/pacts"
|
31
|
+
File.open("spec/pacts/consumer-provider.json", "w") { |file| file << pact_hash.to_json }
|
32
|
+
pact_broker_client.stub_chain(:pacticipants, :versions, :pacts).and_return(pacts_client)
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "call" do
|
36
|
+
|
37
|
+
it "uses the pact_broker client to publish the given pact" do
|
38
|
+
pacts_client.should_receive(:publish).with(pact_json: pact_hash.to_json, consumer_version: consumer_version)
|
39
|
+
subject.call
|
40
|
+
end
|
41
|
+
|
42
|
+
context "when publishing is successful" do
|
43
|
+
it "returns true" do
|
44
|
+
expect(subject.call).to be_true
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "when publishing one or more pacts fails" do
|
49
|
+
let(:pact_files) { ['spec/pacts/doesnotexist.json','spec/pacts/consumer-provider.json']}
|
50
|
+
before do
|
51
|
+
$stderr.stub(:puts)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "logs an message to stderr" do
|
55
|
+
$stderr.should_receive(:puts).with(/Failed to publish pact/)
|
56
|
+
subject.call
|
57
|
+
end
|
58
|
+
|
59
|
+
it "continues publishing the rest" do
|
60
|
+
pacts_client.should_receive(:publish).with(pact_json: pact_hash.to_json, consumer_version: consumer_version)
|
61
|
+
subject.call
|
62
|
+
end
|
63
|
+
|
64
|
+
it "returns false" do
|
65
|
+
expect(subject.call).to be_false
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context "when no pact files are specified" do
|
70
|
+
let(:pact_files) { [] }
|
71
|
+
it "raises a validation error" do
|
72
|
+
expect { subject.call }.to raise_error(/No pact files found/)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context "when consumer_version is blank" do
|
77
|
+
let(:consumer_version) { " " }
|
78
|
+
it "raises a validation error" do
|
79
|
+
expect { subject.call }.to raise_error(/Please specify the consumer_version/)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context "when pact_broker_base_url is blank" do
|
84
|
+
let(:pact_broker_base_url) { " " }
|
85
|
+
it "raises a validation errror" do
|
86
|
+
expect { subject.call }.to raise_error(/Please specify the pact_broker_base_url/)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'pact_broker/client/tasks/publication_task'
|
3
|
+
require 'pact_broker/client/publish_pacts'
|
4
|
+
|
5
|
+
module PactBroker::Client
|
6
|
+
|
7
|
+
describe PublicationTask do
|
8
|
+
|
9
|
+
before do
|
10
|
+
@consumer_version = "1.2.3"
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:publish_pacts) { instance_double("PactBroker::ClientSupport::PublishPacts")}
|
14
|
+
let(:pact_file_list) { ['spec/pact/consumer-provider.json'] }
|
15
|
+
|
16
|
+
before do
|
17
|
+
PactBroker::Client::PublishPacts.stub(:new).and_return(publish_pacts)
|
18
|
+
FileList.should_receive(:[]).with(pattern).and_return(pact_file_list)
|
19
|
+
end
|
20
|
+
|
21
|
+
let(:pattern) { "spec/pacts/*.json" }
|
22
|
+
|
23
|
+
describe "default task" do
|
24
|
+
|
25
|
+
before :all do
|
26
|
+
PactBroker::Client::PublicationTask.new do | task |
|
27
|
+
task.consumer_version = '1.2.3'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "when pacts are succesfully published" do
|
32
|
+
it "invokes PublishPacts with the default values" do
|
33
|
+
PactBroker::Client::PublishPacts.should_receive(:new).with('http://pact-broker', pact_file_list, '1.2.3').and_return(publish_pacts)
|
34
|
+
publish_pacts.should_receive(:call).and_return(true)
|
35
|
+
Rake::Task['pact:publish'].execute
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "when a pact fails to be published" do
|
40
|
+
it "raises an error" do
|
41
|
+
publish_pacts.should_receive(:call).and_return(false)
|
42
|
+
expect { Rake::Task['pact:publish'].execute }.to raise_error("One or more pacts failed to be published")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
describe "custom task" do
|
49
|
+
|
50
|
+
before :all do
|
51
|
+
@pact_broker_base_url = "http://some-host"
|
52
|
+
@pattern = "pact/*.json"
|
53
|
+
PactBroker::Client::PublicationTask.new(:custom) do | task |
|
54
|
+
task.consumer_version = '1.2.3'
|
55
|
+
task.pact_broker_base_url = @pact_broker_base_url
|
56
|
+
task.pattern = @pattern
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
let(:pattern) { @pattern }
|
61
|
+
|
62
|
+
it "invokes PublishPacts with the customised values" do
|
63
|
+
PactBroker::Client::PublishPacts.should_receive(:new).with(@pact_broker_base_url, pact_file_list, '1.2.3')
|
64
|
+
publish_pacts.should_receive(:call).and_return(true)
|
65
|
+
Rake::Task['pact:publish:custom'].execute
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
@@ -0,0 +1,365 @@
|
|
1
|
+
{
|
2
|
+
"provider": {
|
3
|
+
"name": "Pact Broker"
|
4
|
+
},
|
5
|
+
"consumer": {
|
6
|
+
"name": "Pact Broker Client"
|
7
|
+
},
|
8
|
+
"interactions": [
|
9
|
+
{
|
10
|
+
"description": "a request to publish a pact",
|
11
|
+
"provider_state": "the 'Pricing Service' already exists in the pact-broker",
|
12
|
+
"request": {
|
13
|
+
"method": "put",
|
14
|
+
"path": "/pacticipant/Condor/versions/1.3.0/pacts/Pricing%20Service",
|
15
|
+
"body": {
|
16
|
+
"consumer": {
|
17
|
+
"name": "Condor"
|
18
|
+
},
|
19
|
+
"provider": {
|
20
|
+
"name": "Pricing Service"
|
21
|
+
},
|
22
|
+
"interactions": [
|
23
|
+
|
24
|
+
]
|
25
|
+
},
|
26
|
+
"headers": {
|
27
|
+
"Content-Type": "application/json"
|
28
|
+
}
|
29
|
+
},
|
30
|
+
"response": {
|
31
|
+
"headers": {
|
32
|
+
},
|
33
|
+
"status": 201
|
34
|
+
}
|
35
|
+
},
|
36
|
+
{
|
37
|
+
"description": "a request to publish a pact",
|
38
|
+
"provider_state": "the 'Pricing Service' and 'Condor' already exist in the pact-broker, and Condor already has a pact published for version 1.3.0",
|
39
|
+
"request": {
|
40
|
+
"method": "put",
|
41
|
+
"path": "/pacticipant/Condor/versions/1.3.0/pacts/Pricing%20Service",
|
42
|
+
"body": {
|
43
|
+
"consumer": {
|
44
|
+
"name": "Condor"
|
45
|
+
},
|
46
|
+
"provider": {
|
47
|
+
"name": "Pricing Service"
|
48
|
+
},
|
49
|
+
"interactions": [
|
50
|
+
|
51
|
+
]
|
52
|
+
},
|
53
|
+
"headers": {
|
54
|
+
"Content-Type": "application/json"
|
55
|
+
}
|
56
|
+
},
|
57
|
+
"response": {
|
58
|
+
"headers": {
|
59
|
+
},
|
60
|
+
"status": 200
|
61
|
+
}
|
62
|
+
},
|
63
|
+
{
|
64
|
+
"description": "a request to publish a pact",
|
65
|
+
"provider_state": "'Condor' already exist in the pact-broker, but the 'Pricing Service' does not",
|
66
|
+
"request": {
|
67
|
+
"method": "put",
|
68
|
+
"path": "/pacticipant/Condor/versions/1.3.0/pacts/Pricing%20Service",
|
69
|
+
"body": {
|
70
|
+
"consumer": {
|
71
|
+
"name": "Condor"
|
72
|
+
},
|
73
|
+
"provider": {
|
74
|
+
"name": "Pricing Service"
|
75
|
+
},
|
76
|
+
"interactions": [
|
77
|
+
|
78
|
+
]
|
79
|
+
},
|
80
|
+
"headers": {
|
81
|
+
"Content-Type": "application/json"
|
82
|
+
}
|
83
|
+
},
|
84
|
+
"response": {
|
85
|
+
"headers": {
|
86
|
+
},
|
87
|
+
"status": 201
|
88
|
+
}
|
89
|
+
},
|
90
|
+
{
|
91
|
+
"description": "a request to publish a pact",
|
92
|
+
"provider_state": "an error occurs while publishing a pact",
|
93
|
+
"request": {
|
94
|
+
"method": "put",
|
95
|
+
"path": "/pacticipant/Condor/versions/1.3.0/pacts/Pricing%20Service",
|
96
|
+
"body": {
|
97
|
+
"consumer": {
|
98
|
+
"name": "Condor"
|
99
|
+
},
|
100
|
+
"provider": {
|
101
|
+
"name": "Pricing Service"
|
102
|
+
},
|
103
|
+
"interactions": [
|
104
|
+
|
105
|
+
]
|
106
|
+
},
|
107
|
+
"headers": {
|
108
|
+
"Content-Type": "application/json"
|
109
|
+
}
|
110
|
+
},
|
111
|
+
"response": {
|
112
|
+
"status": 500,
|
113
|
+
"headers": {
|
114
|
+
},
|
115
|
+
"body": {
|
116
|
+
"message": {
|
117
|
+
"json_class": "Pact::Term",
|
118
|
+
"data": {
|
119
|
+
"generate": "An error occurred",
|
120
|
+
"matcher": {"json_class":"Regexp","o":0,"s":".*"}
|
121
|
+
}
|
122
|
+
}
|
123
|
+
}
|
124
|
+
}
|
125
|
+
},
|
126
|
+
{
|
127
|
+
"description": "a request to register the repository URL of a pacticipant",
|
128
|
+
"provider_state": "the 'Pricing Service' does not exist in the pact-broker",
|
129
|
+
"request": {
|
130
|
+
"method": "patch",
|
131
|
+
"path": "/pacticipant/Pricing%20Service",
|
132
|
+
"body": {
|
133
|
+
"repository_url": "git@git.realestate.com.au:business-systems/condor.git"
|
134
|
+
},
|
135
|
+
"headers": {
|
136
|
+
"Content-Type": "application/json+patch"
|
137
|
+
}
|
138
|
+
},
|
139
|
+
"response": {
|
140
|
+
"status": 201,
|
141
|
+
"headers": {
|
142
|
+
}
|
143
|
+
}
|
144
|
+
},
|
145
|
+
{
|
146
|
+
"description": "a request to register the repository URL of a pacticipant",
|
147
|
+
"provider_state": "the 'Pricing Service' already exists in the pact-broker",
|
148
|
+
"request": {
|
149
|
+
"method": "patch",
|
150
|
+
"path": "/pacticipant/Pricing%20Service",
|
151
|
+
"body": {
|
152
|
+
"repository_url": "git@git.realestate.com.au:business-systems/condor.git"
|
153
|
+
},
|
154
|
+
"headers": {
|
155
|
+
"Content-Type": "application/json+patch"
|
156
|
+
}
|
157
|
+
},
|
158
|
+
"response": {
|
159
|
+
"status": 200,
|
160
|
+
"headers": {
|
161
|
+
}
|
162
|
+
}
|
163
|
+
},
|
164
|
+
{
|
165
|
+
"description": "a request to retrieve the repository URL of the 'Pricing Service'",
|
166
|
+
"provider_state": "the 'Pricing Service' does not exist in the pact-broker",
|
167
|
+
"request": {
|
168
|
+
"method": "get",
|
169
|
+
"path": "/pacticipant/Pricing%20Service/repository_url",
|
170
|
+
"headers": {
|
171
|
+
"Accept": "text/plain"
|
172
|
+
}
|
173
|
+
},
|
174
|
+
"response": {
|
175
|
+
"status": 404,
|
176
|
+
"headers": {
|
177
|
+
}
|
178
|
+
}
|
179
|
+
},
|
180
|
+
{
|
181
|
+
"description": "a request to retrieve the repository URL of the 'Pricing Service'",
|
182
|
+
"provider_state": "the 'Pricing Service' already exists in the pact-broker",
|
183
|
+
"request": {
|
184
|
+
"method": "get",
|
185
|
+
"path": "/pacticipant/Pricing%20Service/repository_url",
|
186
|
+
"headers": {
|
187
|
+
"Accept": "text/plain"
|
188
|
+
}
|
189
|
+
},
|
190
|
+
"response": {
|
191
|
+
"status": 200,
|
192
|
+
"headers": {
|
193
|
+
"Content-Type": "text/plain;charset=utf-8"
|
194
|
+
},
|
195
|
+
"body": "git@git.realestate.com.au:business-systems/condor.git"
|
196
|
+
}
|
197
|
+
},
|
198
|
+
{
|
199
|
+
"description": "a request to tag the production version of Condor",
|
200
|
+
"provider_state": "'Condor' exists in the pact-broker",
|
201
|
+
"request": {
|
202
|
+
"method": "patch",
|
203
|
+
"path": "/pacticipant/Condor/versions/1.3.0",
|
204
|
+
"body": {
|
205
|
+
"tags": [
|
206
|
+
"prod"
|
207
|
+
],
|
208
|
+
"repository_ref": "packages/condor-1.3.0",
|
209
|
+
"repository_url": "git@git.realestate.com.au:business-systems/condor.git"
|
210
|
+
},
|
211
|
+
"headers": {
|
212
|
+
"Content-Type": "application/json+patch"
|
213
|
+
}
|
214
|
+
},
|
215
|
+
"response": {
|
216
|
+
"status": 200,
|
217
|
+
"headers": {
|
218
|
+
}
|
219
|
+
}
|
220
|
+
},
|
221
|
+
{
|
222
|
+
"description": "a request to tag the production version of Condor",
|
223
|
+
"provider_state": "'Condor' does not exist in the pact-broker",
|
224
|
+
"request": {
|
225
|
+
"method": "patch",
|
226
|
+
"path": "/pacticipant/Condor/versions/1.3.0",
|
227
|
+
"body": {
|
228
|
+
"tags": [
|
229
|
+
"prod"
|
230
|
+
],
|
231
|
+
"repository_ref": "packages/condor-1.3.0",
|
232
|
+
"repository_url": "git@git.realestate.com.au:business-systems/condor.git"
|
233
|
+
},
|
234
|
+
"headers": {
|
235
|
+
"Content-Type": "application/json+patch"
|
236
|
+
}
|
237
|
+
},
|
238
|
+
"response": {
|
239
|
+
"status": 201,
|
240
|
+
"headers": {
|
241
|
+
}
|
242
|
+
}
|
243
|
+
},
|
244
|
+
{
|
245
|
+
"description": "a request to retrieve the latest pact between Condor and the Pricing Service",
|
246
|
+
"provider_state": "a pact between Condor and the Pricing Service exists",
|
247
|
+
"request": {
|
248
|
+
"method": "get",
|
249
|
+
"path": "/pacticipant/Condor/versions/last/pacts/Pricing%20Service",
|
250
|
+
"headers": {
|
251
|
+
"Accept": "application/json"
|
252
|
+
}
|
253
|
+
},
|
254
|
+
"response": {
|
255
|
+
"status": 200,
|
256
|
+
"headers": {
|
257
|
+
"Content-Type": "application/json;charset=utf-8",
|
258
|
+
"X-Pact-Consumer-Version": "1.3.0"
|
259
|
+
},
|
260
|
+
"body": {
|
261
|
+
"consumer": {
|
262
|
+
"name": "Condor"
|
263
|
+
},
|
264
|
+
"provider": {
|
265
|
+
"name": "Pricing Service"
|
266
|
+
},
|
267
|
+
"interactions": [
|
268
|
+
|
269
|
+
]
|
270
|
+
}
|
271
|
+
}
|
272
|
+
},
|
273
|
+
{
|
274
|
+
"description": "a request to retrieve the latest pact between Condor and the Pricing Service",
|
275
|
+
"provider_state": "no pact between Condor and the Pricing Service exists",
|
276
|
+
"request": {
|
277
|
+
"method": "get",
|
278
|
+
"path": "/pacticipant/Condor/versions/last/pacts/Pricing%20Service",
|
279
|
+
"headers": {
|
280
|
+
"Accept": "application/json"
|
281
|
+
}
|
282
|
+
},
|
283
|
+
"response": {
|
284
|
+
"status": 404,
|
285
|
+
"headers": {
|
286
|
+
}
|
287
|
+
}
|
288
|
+
},
|
289
|
+
{
|
290
|
+
"description": "a request to retrieve the pact between the production verison of Condor and the Pricing Service",
|
291
|
+
"provider_state": "a pact between Condor and the Pricing Service exists for the production version of Condor",
|
292
|
+
"request": {
|
293
|
+
"method": "get",
|
294
|
+
"path": "/pacticipant/Condor/versions/last/pacts/Pricing%20Service",
|
295
|
+
"headers": {
|
296
|
+
"Accept": "application/json"
|
297
|
+
},
|
298
|
+
"query": "tag=prod"
|
299
|
+
},
|
300
|
+
"response": {
|
301
|
+
"status": 200,
|
302
|
+
"headers": {
|
303
|
+
},
|
304
|
+
"body": {
|
305
|
+
"consumer": {
|
306
|
+
"name": "Condor"
|
307
|
+
},
|
308
|
+
"provider": {
|
309
|
+
"name": "Pricing Service"
|
310
|
+
},
|
311
|
+
"interactions": [
|
312
|
+
|
313
|
+
]
|
314
|
+
}
|
315
|
+
}
|
316
|
+
},
|
317
|
+
{
|
318
|
+
"description": "a request for the latest version tagged with 'prod'",
|
319
|
+
"provider_state": "a version with production details exists for the Pricing Service",
|
320
|
+
"request": {
|
321
|
+
"method": "get",
|
322
|
+
"path": "/pacticipant/Pricing%20Service/versions/last",
|
323
|
+
"headers": {
|
324
|
+
"Accept": "application/json"
|
325
|
+
},
|
326
|
+
"query": "tag=prod"
|
327
|
+
},
|
328
|
+
"response": {
|
329
|
+
"status": 200,
|
330
|
+
"headers": {
|
331
|
+
"Content-Type": "application/json;charset=utf-8"
|
332
|
+
},
|
333
|
+
"body": {
|
334
|
+
"number": "1.2.3",
|
335
|
+
"repository_url": "git@git.realestate.com.au:business-systems/pricing-service.git",
|
336
|
+
"repository_ref": "package/pricing-service-1.2.3",
|
337
|
+
"tags": [
|
338
|
+
"prod"
|
339
|
+
]
|
340
|
+
}
|
341
|
+
}
|
342
|
+
},
|
343
|
+
{
|
344
|
+
"description": "a request for the latest version",
|
345
|
+
"provider_state": "no version exists for the Pricing Service",
|
346
|
+
"request": {
|
347
|
+
"method": "get",
|
348
|
+
"path": "/pacticipant/Pricing%20Service/versions/last",
|
349
|
+
"headers": {
|
350
|
+
"Accept": "application/json"
|
351
|
+
}
|
352
|
+
},
|
353
|
+
"response": {
|
354
|
+
"status": 404,
|
355
|
+
"headers": {
|
356
|
+
}
|
357
|
+
}
|
358
|
+
}
|
359
|
+
],
|
360
|
+
"metadata": {
|
361
|
+
"pact_gem": {
|
362
|
+
"version": "1.0.15"
|
363
|
+
}
|
364
|
+
}
|
365
|
+
}
|