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.
@@ -0,0 +1,363 @@
1
+ require_relative 'pact_helper'
2
+ require 'pact_broker/client'
3
+
4
+ def silence_warnings
5
+ old_verbose, $VERBOSE = $VERBOSE, nil
6
+ yield
7
+ ensure
8
+ $VERBOSE = old_verbose
9
+ end
10
+
11
+ module PactBroker::Client
12
+ describe PactBrokerClient, :pact => true do
13
+
14
+ before do
15
+ @backup_version = PactBroker::Client::VERSION
16
+ silence_warnings do
17
+ PactBroker::Client::VERSION = "2.0.0"
18
+ end
19
+ end
20
+
21
+ after do
22
+ silence_warnings do
23
+ PactBroker::Client::VERSION = @backup_version
24
+ end
25
+ end
26
+
27
+ let(:pact_hash) { {consumer: {name: 'Condor'}, provider: {name: 'Pricing Service'}, interactions: []} }
28
+ let(:consumer_contract) { Pact::ConsumerContract.from_hash pact_hash }
29
+ let(:pact_json) { pact_hash.to_json }
30
+ let(:pact_broker_client) { PactBrokerClient.new(base_url: 'http://localhost:1234') }
31
+ let(:consumer_version) { '1.3.0' }
32
+ let(:version) { '1.3.0' }
33
+ let(:pact_broker_version) { Pact::Term.new(:matcher => /\d+\.\d+\.\d+/, :generate => '1.0.0') }
34
+ let(:pact_broker_response_headers) { {} }
35
+ let(:default_request_headers) { { 'Content-Type' => 'application/json'} }
36
+ let(:patch_request_headers) { { 'Content-Type' => 'application/json+patch'} }
37
+ let(:get_request_headers) { { 'Accept' => 'application/json'} }
38
+
39
+ describe "publishing a pact" do
40
+
41
+ let(:options) { { pact: pact_json, consumer_version: consumer_version }}
42
+
43
+ context "when the provider already exists in the pact-broker" do
44
+ before do
45
+ pact_broker.
46
+ given("the 'Pricing Service' already exists in the pact-broker").
47
+ upon_receiving("a request to publish a pact").
48
+ with({
49
+ method: :put,
50
+ path: '/pacticipant/Condor/versions/1.3.0/pacts/Pricing%20Service',
51
+ headers: default_request_headers,
52
+ body: pact_hash }).
53
+ will_respond_with( headers: pact_broker_response_headers,
54
+ status: 201
55
+ )
56
+ end
57
+ it "returns true" do
58
+ pact_broker_client.pacticipants.versions.pacts.publish options
59
+ end
60
+ end
61
+
62
+ context "when the provider, consumer, pact and version already exist in the pact-broker" do
63
+ before do
64
+ pact_broker.
65
+ given("the 'Pricing Service' and 'Condor' already exist in the pact-broker, and Condor already has a pact published for version 1.3.0").
66
+ upon_receiving("a request to publish a pact").
67
+ with({
68
+ method: :put,
69
+ path: '/pacticipant/Condor/versions/1.3.0/pacts/Pricing%20Service',
70
+ headers: default_request_headers,
71
+ body: pact_hash }).
72
+ will_respond_with( headers: pact_broker_response_headers,
73
+ status: 200
74
+ )
75
+ end
76
+ it "returns true" do
77
+ pact_broker_client.pacticipants.versions.pacts.publish options
78
+ end
79
+ end
80
+
81
+ context "when the provider does not exist, but the consumer, pact and version already exist in the pact-broker" do
82
+ before do
83
+ pact_broker.
84
+ given("'Condor' already exist in the pact-broker, but the 'Pricing Service' does not").
85
+ upon_receiving("a request to publish a pact").
86
+ with({
87
+ method: :put,
88
+ path: '/pacticipant/Condor/versions/1.3.0/pacts/Pricing%20Service',
89
+ headers: default_request_headers,
90
+ body: pact_hash }).
91
+ will_respond_with( headers: pact_broker_response_headers,
92
+ status: 201
93
+ )
94
+ end
95
+ it "returns true" do
96
+ pact_broker_client.pacticipants.versions.pacts.publish options
97
+ end
98
+ end
99
+
100
+ context "when publishing is not successful" do
101
+ before do
102
+ pact_broker.
103
+ given("an error occurs while publishing a pact").
104
+ upon_receiving("a request to publish a pact").
105
+ with({
106
+ method: :put,
107
+ path: '/pacticipant/Condor/versions/1.3.0/pacts/Pricing%20Service',
108
+ headers: default_request_headers,
109
+ body: pact_hash }).
110
+ will_respond_with({
111
+ status: 500,
112
+ headers: pact_broker_response_headers,
113
+ body: {
114
+ message: Pact::Term.new(matcher: /.*/, generate: 'An error occurred')
115
+ }
116
+ })
117
+ end
118
+ it "raises an error" do
119
+ expect { pact_broker_client.pacticipants.versions.pacts.publish options }.to raise_error /An error occurred/
120
+ end
121
+ end
122
+
123
+ end
124
+
125
+ let(:repository_url ) { "git@git.realestate.com.au:business-systems/condor.git" }
126
+
127
+ describe "registering a repository url" do
128
+ context "where the pacticipant does not already exist in the pact-broker" do
129
+ before do
130
+ pact_broker.
131
+ given("the 'Pricing Service' does not exist in the pact-broker").
132
+ upon_receiving("a request to register the repository URL of a pacticipant").
133
+ with(
134
+ method: :patch,
135
+ path: '/pacticipant/Pricing%20Service',
136
+ headers: patch_request_headers,
137
+ body: {repository_url: repository_url} ).
138
+ will_respond_with(
139
+ status: 201,
140
+ headers: pact_broker_response_headers
141
+ )
142
+ end
143
+ it "returns true" do
144
+ expect(pact_broker_client.pacticipants.update({:pacticipant => 'Pricing Service', :repository_url => repository_url})).to be_true
145
+ end
146
+ end
147
+ context "where the 'Pricing Service' exists in the pact-broker" do
148
+ before do
149
+ pact_broker.
150
+ given("the 'Pricing Service' already exists in the pact-broker").
151
+ upon_receiving("a request to register the repository URL of a pacticipant").
152
+ with(
153
+ method: :patch,
154
+ path: '/pacticipant/Pricing%20Service',
155
+ headers: patch_request_headers,
156
+ body: {repository_url: repository_url} ).
157
+ will_respond_with(
158
+ status: 200,
159
+ headers: pact_broker_response_headers
160
+ )
161
+ end
162
+ it "returns true" do
163
+ expect(pact_broker_client.pacticipants.update({:pacticipant => 'Pricing Service', :repository_url => repository_url})).to be_true
164
+ end
165
+ end
166
+ end
167
+
168
+ describe "retrieving a repository url" do
169
+ context "where the pacticipant does not already exist in the pact-broker" do
170
+ before do
171
+ pact_broker.
172
+ given("the 'Pricing Service' does not exist in the pact-broker").
173
+ upon_receiving("a request to retrieve the repository URL of the 'Pricing Service'").
174
+ with(
175
+ method: :get,
176
+ path: '/pacticipant/Pricing%20Service/repository_url',
177
+ headers: get_request_headers.merge({'Accept' => 'text/plain'})).
178
+ will_respond_with(
179
+ status: 404,
180
+ headers: pact_broker_response_headers
181
+ )
182
+ end
183
+ it "returns nil" do
184
+ expect(pact_broker_client.pacticipants.repository_url({:pacticipant => 'Pricing Service'})).to eq(nil)
185
+ end
186
+ end
187
+ context "where the 'Pricing Service' exists in the pact-broker" do
188
+ before do
189
+ pact_broker.
190
+ given("the 'Pricing Service' already exists in the pact-broker").
191
+ upon_receiving("a request to retrieve the repository URL of the 'Pricing Service'").
192
+ with(
193
+ method: :get,
194
+ path: '/pacticipant/Pricing%20Service/repository_url',
195
+ headers: get_request_headers.merge({'Accept' => 'text/plain'})).
196
+ will_respond_with(
197
+ status: 200,
198
+ headers: pact_broker_response_headers.merge({'Content-Type' => 'text/plain;charset=utf-8'}),
199
+ body: repository_url
200
+ )
201
+ end
202
+ it "returns the URL" do
203
+ expect(pact_broker_client.pacticipants.repository_url({:pacticipant => 'Pricing Service'})).to eq repository_url
204
+ end
205
+ end
206
+ end
207
+
208
+ describe "tagging a version with prod details" do
209
+ let(:repository_ref) { "packages/condor-#{version}" }
210
+
211
+ let(:tag_options) { {pacticipant: 'Condor', version: version, repository_ref: repository_ref, repository_url: repository_url, :tag => 'prod'} }
212
+ context "when the component exists" do
213
+ before do
214
+ pact_broker.
215
+ given("'Condor' exists in the pact-broker").
216
+ upon_receiving("a request to tag the production version of Condor").
217
+ with(
218
+ method: :patch,
219
+ path: '/pacticipant/Condor/versions/1.3.0',
220
+ headers: patch_request_headers,
221
+ body: {:tags => ['prod'], :repository_ref => repository_ref, :repository_url => repository_url} ).
222
+ will_respond_with(
223
+ status: 200,
224
+ headers: pact_broker_response_headers
225
+ )
226
+ end
227
+ it "returns true" do
228
+ expect(pact_broker_client.pacticipants.versions.update tag_options).to be_true
229
+ end
230
+ end
231
+ context "when the component does not exist" do
232
+ before do
233
+ pact_broker.
234
+ given("'Condor' does not exist in the pact-broker").
235
+ upon_receiving("a request to tag the production version of Condor").
236
+ with(
237
+ method: :patch,
238
+ path: '/pacticipant/Condor/versions/1.3.0',
239
+ headers: patch_request_headers,
240
+ body: {:tags => ['prod'], :repository_ref => repository_ref, :repository_url => repository_url} ).
241
+ will_respond_with(
242
+ status: 201,
243
+ headers: pact_broker_response_headers
244
+ )
245
+ end
246
+ it "returns true" do
247
+ expect(pact_broker_client.pacticipants.versions.update tag_options).to be_true
248
+ end
249
+ end
250
+ end
251
+
252
+ describe "retrieving a pact" do
253
+ describe "finding the latest version" do
254
+ context "when a pact is found" do
255
+
256
+ let(:response_headers) { pact_broker_response_headers.merge({'Content-Type' => 'application/json;charset=utf-8', 'X-Pact-Consumer-Version' => consumer_version}) }
257
+ before do
258
+ pact_broker.
259
+ given("a pact between Condor and the Pricing Service exists").
260
+ upon_receiving("a request to retrieve the latest pact between Condor and the Pricing Service").
261
+ with({
262
+ method: :get,
263
+ path: '/pacticipant/Condor/versions/last/pacts/Pricing%20Service',
264
+ headers: get_request_headers
265
+ }).
266
+ will_respond_with({
267
+ status: 200,
268
+ headers: response_headers,
269
+ body: pact_hash
270
+ })
271
+ end
272
+
273
+ it "returns the pact json" do
274
+ response = pact_broker_client.pacticipants.versions.pacts.last consumer: 'Condor', provider: 'Pricing Service'
275
+ expect(response).to eq(pact_json)
276
+ end
277
+
278
+ end
279
+ context "when no pact is found" do
280
+ before do
281
+ pact_broker.
282
+ given("no pact between Condor and the Pricing Service exists").
283
+ upon_receiving("a request to retrieve the latest pact between Condor and the Pricing Service").
284
+ with({
285
+ method: :get,
286
+ path: '/pacticipant/Condor/versions/last/pacts/Pricing%20Service',
287
+ headers: get_request_headers
288
+ }).
289
+ will_respond_with({
290
+ status: 404,
291
+ headers: pact_broker_response_headers
292
+ })
293
+ end
294
+ it "returns nil" do
295
+ response = pact_broker_client.pacticipants.versions.pacts.last consumer: 'Condor', provider: 'Pricing Service'
296
+ expect(response).to eq(nil)
297
+ end
298
+ end
299
+ end
300
+ describe "finding the latest production version" do
301
+ context "when a pact is found" do
302
+ before do
303
+ pact_broker.
304
+ given("a pact between Condor and the Pricing Service exists for the production version of Condor").
305
+ upon_receiving("a request to retrieve the pact between the production verison of Condor and the Pricing Service").
306
+ with({
307
+ method: :get,
308
+ path: '/pacticipant/Condor/versions/last/pacts/Pricing%20Service',
309
+ query: 'tag=prod',
310
+ headers: get_request_headers
311
+ }).
312
+ will_respond_with({
313
+ status: 200,
314
+ headers: {'Content-Type' => 'application/json;charset=utf-8', 'X-Pact-Consumer-Version' => consumer_version},
315
+ body: pact_hash,
316
+ headers: pact_broker_response_headers
317
+ })
318
+ end
319
+
320
+ it "returns the pact json" do
321
+ response = pact_broker_client.pacticipants.versions.pacts.last consumer: 'Condor', provider: 'Pricing Service', tag: 'prod'
322
+ expect(response).to eq(pact_json)
323
+ end
324
+ end
325
+ end
326
+ end
327
+
328
+ describe "retriving versions" do
329
+ context "when retrieving the production details of a version" do
330
+ context "when a version is found" do
331
+ let(:repository_url) { "git@git.realestate.com.au:business-systems/pricing-service.git" }
332
+ let(:repository_ref) { "package/pricing-service-1.2.3"}
333
+ let(:tags) { ['prod']}
334
+ let(:body) { { number: '1.2.3', repository_url: repository_url, repository_ref: repository_ref, tags: tags } }
335
+ before do
336
+ pact_broker.
337
+ given("a version with production details exists for the Pricing Service").
338
+ upon_receiving("a request for the latest version tagged with 'prod'").
339
+ with(method: :get, path: '/pacticipant/Pricing%20Service/versions/last', query: 'tag=prod', headers: get_request_headers).
340
+ will_respond_with( status: 200,
341
+ headers: pact_broker_response_headers.merge({'Content-Type' => 'application/json;charset=utf-8'}),
342
+ body: body )
343
+ end
344
+ it 'returns the version details' do
345
+ expect( pact_broker_client.pacticipants.versions.last pacticipant: 'Pricing Service', tag: 'prod' ).to eq body
346
+ end
347
+ end
348
+ end
349
+ context "when a version is not found" do
350
+ before do
351
+ pact_broker.
352
+ given("no version exists for the Pricing Service").
353
+ upon_receiving("a request for the latest version").
354
+ with(method: :get, path: '/pacticipant/Pricing%20Service/versions/last', headers: get_request_headers).
355
+ will_respond_with( status: 404, headers: pact_broker_response_headers )
356
+ end
357
+ it 'returns nil' do
358
+ expect( pact_broker_client.pacticipants.versions.last pacticipant: 'Pricing Service' ).to eq nil
359
+ end
360
+ end
361
+ end
362
+ end
363
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+ require 'pact/consumer/rspec'
3
+
4
+
5
+ Pact.service_consumer 'Pact Broker Client' do
6
+
7
+ has_pact_with "Pact Broker" do
8
+ mock_service :pact_broker do
9
+ port 1234
10
+ end
11
+ end
12
+
13
+ end
14
+
@@ -0,0 +1,5 @@
1
+ require 'rspec/fire'
2
+
3
+ RSpec.configure do | config |
4
+ config.include RSpec::Fire
5
+ end
metadata ADDED
@@ -0,0 +1,213 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pact_broker-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Bethany Skurrie
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-11-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: pact
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: httparty
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: json
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 10.0.3
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 10.0.3
78
+ - !ruby/object:Gem::Dependency
79
+ name: pry
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: fakefs
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: '0.4'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: '0.4'
110
+ - !ruby/object:Gem::Dependency
111
+ name: rspec-fire
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: debugger
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ description: Publishes pacts to, and retrieves pacts from, the pact broker server.
143
+ email:
144
+ - bskurrie@dius.com.au
145
+ executables: []
146
+ extensions: []
147
+ extra_rdoc_files: []
148
+ files:
149
+ - .gitignore
150
+ - .rspec
151
+ - Gemfile
152
+ - Gemfile.lock
153
+ - README.md
154
+ - Rakefile
155
+ - ci.sh
156
+ - lib/pact_broker/client.rb
157
+ - lib/pact_broker/client/base_client.rb
158
+ - lib/pact_broker/client/pact_broker_client.rb
159
+ - lib/pact_broker/client/pacticipants.rb
160
+ - lib/pact_broker/client/pacts.rb
161
+ - lib/pact_broker/client/publish_pacts.rb
162
+ - lib/pact_broker/client/tasks.rb
163
+ - lib/pact_broker/client/tasks/publication_task.rb
164
+ - lib/pact_broker/client/version.rb
165
+ - lib/pact_broker/client/versions.rb
166
+ - lib/pact_broker_client.rb
167
+ - pact-broker-client.gemspec
168
+ - spec/lib/pact_broker/client/pact_broker_client_spec.rb
169
+ - spec/lib/pact_broker/client/publish_pacts_spec.rb
170
+ - spec/lib/pact_broker/client/tasks/publication_task_spec.rb
171
+ - spec/pacts/pact_broker_client-pact_broker.json
172
+ - spec/service_providers/pact_broker_client_spec.rb
173
+ - spec/service_providers/pact_helper.rb
174
+ - spec/spec_helper.rb
175
+ homepage: https://github.com/bethesque/pact_broker-client.git
176
+ licenses:
177
+ - MIT
178
+ post_install_message:
179
+ rdoc_options: []
180
+ require_paths:
181
+ - lib
182
+ required_ruby_version: !ruby/object:Gem::Requirement
183
+ none: false
184
+ requirements:
185
+ - - ! '>='
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ segments:
189
+ - 0
190
+ hash: 26826033088449580
191
+ required_rubygems_version: !ruby/object:Gem::Requirement
192
+ none: false
193
+ requirements:
194
+ - - ! '>='
195
+ - !ruby/object:Gem::Version
196
+ version: '0'
197
+ segments:
198
+ - 0
199
+ hash: 26826033088449580
200
+ requirements: []
201
+ rubyforge_project:
202
+ rubygems_version: 1.8.23
203
+ signing_key:
204
+ specification_version: 3
205
+ summary: See description
206
+ test_files:
207
+ - spec/lib/pact_broker/client/pact_broker_client_spec.rb
208
+ - spec/lib/pact_broker/client/publish_pacts_spec.rb
209
+ - spec/lib/pact_broker/client/tasks/publication_task_spec.rb
210
+ - spec/pacts/pact_broker_client-pact_broker.json
211
+ - spec/service_providers/pact_broker_client_spec.rb
212
+ - spec/service_providers/pact_helper.rb
213
+ - spec/spec_helper.rb