pact_broker-client 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,6 +1,17 @@
1
1
  Do this to generate your change history
2
2
 
3
- $ git log --date=relative --pretty=format:' * %h - %s (%an, %ad)' 'package/pact_broker-client-0.0.PRODVERSION'..'package/pact_broker-client-0.0.NEWVERSION'
3
+ $ git log --pretty=format:' * %h - %s (%an, %ad)'
4
+
5
+ #### 0.0.6 (2014-03-24)
6
+
7
+ * 2ad5f7d - Updated method of tagging versions (bethesque, Sat Mar 22 16:54:37 2014 +1100)
8
+ * b74128f - Added 'latest' pact url to pact representation in the 'latest pacts' response (bethesque, Sat Mar 22 09:04:31 2014 +1100)
9
+
10
+ #### 0.0.5 (2014-01-03)
11
+
12
+ * 194183c - Removing debugger for Travis CI (bethesque, Fri Jan 3 12:45:07 2014 +1100)
13
+ * b42aba9 - Changed 'last' to 'latest' (bethesque, Tue Nov 19 09:30:12 2013 +1100)
14
+ * 30d63b7 - Changed name to title in list pacticipants response (bethesque, Mon Nov 18 09:37:11 2013 +1100)
4
15
 
5
16
  #### 0.0.4 (2013-11-15)
6
17
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pact_broker-client (0.0.5)
4
+ pact_broker-client (0.0.6)
5
5
  httparty
6
6
  json
7
7
  pact
@@ -9,24 +9,27 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- awesome_print (1.1.0)
12
+ awesome_print (1.2.0)
13
13
  coderay (1.0.9)
14
+ daemons (1.1.9)
14
15
  diff-lcs (1.2.5)
16
+ eventmachine (1.0.3)
15
17
  fakefs (0.4.2)
16
18
  find_a_port (1.0.1)
17
- httparty (0.12.0)
19
+ httparty (0.13.0)
18
20
  json (~> 1.8)
19
21
  multi_xml (>= 0.5.2)
20
22
  json (1.8.1)
21
23
  method_source (0.8.2)
22
24
  multi_xml (0.5.5)
23
- pact (1.0.23)
24
- awesome_print (~> 1.1.0)
25
+ pact (1.0.30)
26
+ awesome_print (~> 1.1)
25
27
  find_a_port (~> 1.0.1)
26
28
  json
27
29
  rack-test (~> 0.6.2)
28
30
  randexp (~> 0.1.7)
29
31
  rspec (~> 2.12)
32
+ thin
30
33
  thor
31
34
  webrick
32
35
  pry (0.9.12.2)
@@ -49,6 +52,10 @@ GEM
49
52
  rspec (~> 2.11)
50
53
  rspec-mocks (2.14.4)
51
54
  slop (3.4.6)
55
+ thin (1.6.1)
56
+ daemons (>= 1.0.9)
57
+ eventmachine (>= 1.0.0)
58
+ rack (>= 1.0.0)
52
59
  thor (0.18.1)
53
60
  webrick (1.3.1)
54
61
 
data/Rakefile CHANGED
@@ -1,33 +1,8 @@
1
- require 'bundler/gem_helper'
2
- module Bundler
3
- class GemHelper
4
- def install
5
- desc "Build #{name}-#{version}.gem into the pkg directory"
6
- task 'build' do
7
- build_gem
8
- end
9
-
10
- desc "Build and install #{name}-#{version}.gem into system gems"
11
- task 'install' do
12
- install_gem
13
- end
14
-
15
- GemHelper.instance = self
16
- end
17
- end
18
- end
19
- Bundler::GemHelper.install_tasks
1
+ require "bundler/gem_tasks"
20
2
  require 'rspec/core/rake_task'
21
- #require 'geminabox-client'
22
3
 
23
4
  Dir.glob('lib/tasks/**/*.rake').each { |task| load "#{Dir.pwd}/#{task}" }
24
5
  Dir.glob('tasks/**/*.rake').each { |task| load "#{Dir.pwd}/#{task}" }
25
6
  RSpec::Core::RakeTask.new(:spec)
26
7
 
27
8
  task :default => [:spec]
28
-
29
- # desc "Release to REA gems host"
30
- # task :publish => :build do
31
- # gem_file = "pkg/pact-broker-client#{PactBroker::Client::VERSION}.gem"
32
- # Geminabox::Client.new('http://rea-rubygems').upload(gem_file)
33
- # end
@@ -1,5 +1,5 @@
1
1
  module PactBroker
2
2
  module Client
3
- VERSION = '0.0.5'
3
+ VERSION = '0.0.6'
4
4
  end
5
5
  end
@@ -7,18 +7,25 @@ module PactBroker
7
7
 
8
8
  def latest options
9
9
  query = options[:tag] ? {tag: options[:tag]} : {}
10
- response = self.class.get("#{version_base_url(options)}/latest", query: query, headers: default_get_headers)
10
+ response = self.class.get("#{versions_base_url(options)}/latest", query: query, headers: default_get_headers)
11
11
 
12
12
  handle_response(response) do
13
13
  string_keys_to_symbols(response.to_hash)
14
14
  end
15
15
  end
16
16
 
17
+ def tag options
18
+ response = put(tag_url(options), headers: default_put_headers.merge("Content-Length" => "0"))
19
+ handle_response(response) do
20
+ true
21
+ end
22
+ end
23
+
17
24
  def update options
18
25
  body = options.select{ | key, v | [:repository_ref, :repository_url, :tags].include?(key)}
19
26
  body[:tags] ||= []
20
27
  (body[:tags] << options[:tag]) if options[:tag]
21
- response = patch("#{version_base_url(options)}/#{options[:version]}", body: body, headers: default_patch_headers)
28
+ response = patch("#{version_base_url(options)}", body: body, headers: default_patch_headers)
22
29
  handle_response(response) do
23
30
  true
24
31
  end
@@ -29,10 +36,20 @@ module PactBroker
29
36
  end
30
37
 
31
38
  private
32
- def version_base_url options
33
- pacticipant = encode_param(options[:pacticipant])
39
+
40
+ def tag_url options
41
+ "#{version_base_url(options)}/tags/#{options.fetch(:tag)}"
42
+ end
43
+
44
+ def versions_base_url options
45
+ pacticipant = encode_param(options.fetch(:pacticipant))
34
46
  "/pacticipants/#{pacticipant}/versions"
35
47
  end
48
+
49
+ def version_base_url options
50
+ version = encode_param(options.fetch(:version))
51
+ "#{versions_base_url(options)}/#{version}"
52
+ end
36
53
  end
37
54
  end
38
55
  end
@@ -29,9 +29,14 @@
29
29
  "pacts": [
30
30
  {
31
31
  "_links": {
32
- "self": {
33
- "href": "http://example.org/pact/provider/Pricing%20Service/consumer/Condor/version/1.3.0"
34
- }
32
+ "self": [
33
+ {
34
+ "href": "http://example.org/pact/provider/Pricing%20Service/consumer/Condor/latest"
35
+ },
36
+ {
37
+ "href": "http://example.org/pact/provider/Pricing%20Service/consumer/Condor/version/1.3.0"
38
+ }
39
+ ]
35
40
  },
36
41
  "_embedded": {
37
42
  "consumer": {
@@ -320,50 +325,6 @@
320
325
  }
321
326
  }
322
327
  },
323
- {
324
- "description": "a request to tag the production version of Condor",
325
- "provider_state": "'Condor' exists in the pact-broker",
326
- "request": {
327
- "method": "patch",
328
- "path": "/pacticipants/Condor/versions/1.3.0",
329
- "body": {
330
- "tags": [
331
- "prod"
332
- ],
333
- "repository_ref": "packages/condor-1.3.0"
334
- },
335
- "headers": {
336
- "Content-Type": "application/json"
337
- }
338
- },
339
- "response": {
340
- "status": 200,
341
- "headers": {
342
- }
343
- }
344
- },
345
- {
346
- "description": "a request to tag the production version of Condor",
347
- "provider_state": "'Condor' does not exist in the pact-broker",
348
- "request": {
349
- "method": "patch",
350
- "path": "/pacticipants/Condor/versions/1.3.0",
351
- "body": {
352
- "tags": [
353
- "prod"
354
- ],
355
- "repository_ref": "packages/condor-1.3.0"
356
- },
357
- "headers": {
358
- "Content-Type": "application/json"
359
- }
360
- },
361
- "response": {
362
- "status": 201,
363
- "headers": {
364
- }
365
- }
366
- },
367
328
  {
368
329
  "description": "a request retrieve a pact for a specific version",
369
330
  "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",
@@ -500,11 +461,98 @@
500
461
  "headers": {
501
462
  }
502
463
  }
464
+ },
465
+ {
466
+ "description": "a request to tag the production version of Condor",
467
+ "provider_state": "'Condor' exists in the pact-broker",
468
+ "request": {
469
+ "method": "put",
470
+ "path": "/pacticipants/Condor/versions/1.3.0/tags/prod",
471
+ "headers": {
472
+ "Content-Type": "application/json"
473
+ }
474
+ },
475
+ "response": {
476
+ "status": 201,
477
+ "headers": {
478
+ },
479
+ "body": {
480
+ "_links": {
481
+ "self": {
482
+ "href": {
483
+ "json_class": "Pact::Term",
484
+ "data": {
485
+ "generate": "http://localhost:1234/pacticipants/Condor/versions/1.3.0/tags/prod",
486
+ "matcher": {"json_class":"Regexp","o":0,"s":"http://.*/pacticipants/Condor/versions/1.3.0/tags/prod"}
487
+ }
488
+ }
489
+ }
490
+ }
491
+ }
492
+ }
493
+ },
494
+ {
495
+ "description": "a request to tag the production version of Condor",
496
+ "provider_state": "'Condor' does not exist in the pact-broker",
497
+ "request": {
498
+ "method": "put",
499
+ "path": "/pacticipants/Condor/versions/1.3.0/tags/prod",
500
+ "headers": {
501
+ "Content-Type": "application/json"
502
+ }
503
+ },
504
+ "response": {
505
+ "status": 201,
506
+ "headers": {
507
+ },
508
+ "body": {
509
+ "_links": {
510
+ "self": {
511
+ "href": {
512
+ "json_class": "Pact::Term",
513
+ "data": {
514
+ "generate": "http://localhost:1234/pacticipants/Condor/versions/1.3.0/tags/prod",
515
+ "matcher": {"json_class":"Regexp","o":0,"s":"http://.*/pacticipants/Condor/versions/1.3.0/tags/prod"}
516
+ }
517
+ }
518
+ }
519
+ }
520
+ }
521
+ }
522
+ },
523
+ {
524
+ "description": "a request to tag the production version of Condor",
525
+ "provider_state": "'Condor' exists in the pact-broker with version 1.3.0, tagged with 'prod'",
526
+ "request": {
527
+ "method": "put",
528
+ "path": "/pacticipants/Condor/versions/1.3.0/tags/prod",
529
+ "headers": {
530
+ "Content-Type": "application/json"
531
+ }
532
+ },
533
+ "response": {
534
+ "status": 200,
535
+ "headers": {
536
+ },
537
+ "body": {
538
+ "_links": {
539
+ "self": {
540
+ "href": {
541
+ "json_class": "Pact::Term",
542
+ "data": {
543
+ "generate": "http://localhost:1234/pacticipants/Condor/versions/1.3.0/tags/prod",
544
+ "matcher": {"json_class":"Regexp","o":0,"s":"http://.*/pacticipants/Condor/versions/1.3.0/tags/prod"}
545
+ }
546
+ }
547
+ }
548
+ }
549
+ }
550
+ }
503
551
  }
504
552
  ],
505
553
  "metadata": {
506
554
  "pact_gem": {
507
- "version": "1.0.20"
555
+ "version": "1.0.23"
508
556
  }
509
557
  }
510
558
  }
@@ -0,0 +1,95 @@
1
+ module PactBroker::Client
2
+ describe PactBrokerClient, :pact => true do
3
+
4
+ include_context "pact broker"
5
+
6
+ describe "publishing a pact" do
7
+
8
+ let(:options) { { pact_json: pact_json, consumer_version: consumer_version }}
9
+
10
+ context "when the provider already exists in the pact-broker" do
11
+ before do
12
+ pact_broker.
13
+ given("the 'Pricing Service' already exists in the pact-broker").
14
+ upon_receiving("a request to publish a pact").
15
+ with(
16
+ method: :put,
17
+ path: '/pact/provider/Pricing%20Service/consumer/Condor/version/1.3.0',
18
+ headers: default_request_headers,
19
+ body: pact_hash ).
20
+ will_respond_with(
21
+ headers: pact_broker_response_headers,
22
+ status: 201
23
+ )
24
+ end
25
+ it "returns true" do
26
+ expect(pact_broker_client.pacticipants.versions.pacts.publish(options)).to be_true
27
+ end
28
+ end
29
+
30
+ context "when the provider, consumer, pact and version already exist in the pact-broker" do
31
+ before do
32
+ pact_broker.
33
+ given("the 'Pricing Service' and 'Condor' already exist in the pact-broker, and Condor already has a pact published for version 1.3.0").
34
+ upon_receiving("a request to publish a pact").
35
+ with(
36
+ method: :put,
37
+ path: '/pact/provider/Pricing%20Service/consumer/Condor/version/1.3.0',
38
+ headers: default_request_headers,
39
+ body: pact_hash ).
40
+ will_respond_with(
41
+ headers: pact_broker_response_headers,
42
+ status: 200
43
+ )
44
+ end
45
+ it "returns true" do
46
+ expect(pact_broker_client.pacticipants.versions.pacts.publish(options)).to be_true
47
+ end
48
+ end
49
+
50
+ context "when the provider does not exist, but the consumer, pact and version already exist in the pact-broker" do
51
+ before do
52
+ pact_broker.
53
+ given("'Condor' already exist in the pact-broker, but the 'Pricing Service' does not").
54
+ upon_receiving("a request to publish a pact").
55
+ with(
56
+ method: :put,
57
+ path: '/pact/provider/Pricing%20Service/consumer/Condor/version/1.3.0',
58
+ headers: default_request_headers,
59
+ body: pact_hash ).
60
+ will_respond_with(
61
+ headers: pact_broker_response_headers,
62
+ status: 201
63
+ )
64
+ end
65
+ it "returns true" do
66
+ expect(pact_broker_client.pacticipants.versions.pacts.publish(options)).to be_true
67
+ end
68
+ end
69
+
70
+ context "when publishing is not successful" do
71
+ before do
72
+ pact_broker.
73
+ given("an error occurs while publishing a pact").
74
+ upon_receiving("a request to publish a pact").
75
+ with(
76
+ method: :put,
77
+ path: '/pact/provider/Pricing%20Service/consumer/Condor/version/1.3.0',
78
+ headers: default_request_headers,
79
+ body: pact_hash ).
80
+ will_respond_with(
81
+ status: 500,
82
+ headers: {'Content-Type' => 'application/json'},
83
+ body: {
84
+ message: Pact::Term.new(matcher: /.*/, generate: 'An error occurred')
85
+ }
86
+ )
87
+ end
88
+ it "raises an error" do
89
+ expect { pact_broker_client.pacticipants.versions.pacts.publish options }.to raise_error /An error occurred/
90
+ end
91
+ end
92
+
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,49 @@
1
+ module PactBroker::Client
2
+ describe Pacticipants, :pact => true do
3
+
4
+ include_context "pact broker"
5
+
6
+ let(:repository_url ) { "git@git.realestate.com.au:business-systems/pricing-service" }
7
+
8
+ describe "registering a repository url" do
9
+ context "where the pacticipant does not already exist in the pact-broker" do
10
+ before do
11
+ pact_broker.
12
+ given("the 'Pricing Service' does not exist in the pact-broker").
13
+ upon_receiving("a request to register the repository URL of a pacticipant").
14
+ with(
15
+ method: :patch,
16
+ path: '/pacticipants/Pricing%20Service',
17
+ headers: patch_request_headers,
18
+ body: {repository_url: repository_url} ).
19
+ will_respond_with(
20
+ status: 201,
21
+ headers: pact_broker_response_headers
22
+ )
23
+ end
24
+ it "returns true" do
25
+ expect(pact_broker_client.pacticipants.update({:pacticipant => 'Pricing Service', :repository_url => repository_url})).to be_true
26
+ end
27
+ end
28
+ context "where the 'Pricing Service' exists in the pact-broker" do
29
+ before do
30
+ pact_broker.
31
+ given("the 'Pricing Service' already exists in the pact-broker").
32
+ upon_receiving("a request to register the repository URL of a pacticipant").
33
+ with(
34
+ method: :patch,
35
+ path: '/pacticipants/Pricing%20Service',
36
+ headers: patch_request_headers,
37
+ body: { repository_url: repository_url }).
38
+ will_respond_with(
39
+ status: 200,
40
+ headers: pact_broker_response_headers
41
+ )
42
+ end
43
+ it "returns true" do
44
+ expect(pact_broker_client.pacticipants.update({:pacticipant => 'Pricing Service', :repository_url => repository_url})).to be_true
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,149 @@
1
+ require_relative 'pact_helper'
2
+ require 'pact_broker/client'
3
+
4
+ module PactBroker::Client
5
+ describe Pacts, :pact => true do
6
+
7
+ include_context "pact broker"
8
+
9
+ describe "retrieving a pact" do
10
+ describe "retriving a specific version" do
11
+ before do
12
+ pact_broker.
13
+ given("the 'Pricing Service' and 'Condor' already exist in the pact-broker, and Condor already has a pact published for version 1.3.0").
14
+ upon_receiving("a request retrieve a pact for a specific version").
15
+ with(
16
+ method: :get,
17
+ path: '/pact/provider/Pricing%20Service/consumer/Condor/version/1.3.0',
18
+ headers: {} ).
19
+ will_respond_with(
20
+ headers: pact_broker_response_headers,
21
+ status: 200,
22
+ body: pact_hash
23
+ )
24
+ end
25
+ it "returns the pact json" do
26
+ response = pact_broker_client.pacticipants.versions.pacts.get consumer: 'Condor', provider: 'Pricing Service', consumer_version: '1.3.0'
27
+ expect(response).to eq(pact_json)
28
+ end
29
+ end
30
+
31
+ describe "finding the latest version" do
32
+ context "when a pact is found" do
33
+
34
+ let(:response_headers) { pact_broker_response_headers.merge({'Content-Type' => 'application/json', 'X-Pact-Consumer-Version' => consumer_version}) }
35
+ before do
36
+ pact_broker.
37
+ given("a pact between Condor and the Pricing Service exists").
38
+ upon_receiving("a request to retrieve the latest pact between Condor and the Pricing Service").
39
+ with(
40
+ method: :get,
41
+ path: '/pact/provider/Pricing%20Service/consumer/Condor/latest',
42
+ headers: {}
43
+ ).
44
+ will_respond_with(
45
+ status: 200,
46
+ headers: response_headers,
47
+ body: pact_hash
48
+ )
49
+ end
50
+
51
+ it "returns the pact json" do
52
+ response = pact_broker_client.pacticipants.versions.pacts.latest consumer: 'Condor', provider: 'Pricing Service'
53
+ expect(response).to eq(pact_json)
54
+ end
55
+
56
+ end
57
+ context "when no pact is found" do
58
+ before do
59
+ pact_broker.
60
+ given("no pact between Condor and the Pricing Service exists").
61
+ upon_receiving("a request to retrieve the latest pact between Condor and the Pricing Service").
62
+ with(
63
+ method: :get,
64
+ path: '/pact/provider/Pricing%20Service/consumer/Condor/latest',
65
+ headers: {}
66
+ ).
67
+ will_respond_with(
68
+ status: 404,
69
+ headers: pact_broker_response_headers
70
+ )
71
+ end
72
+ it "returns nil" do
73
+ response = pact_broker_client.pacticipants.versions.pacts.latest consumer: 'Condor', provider: 'Pricing Service'
74
+ expect(response).to eq(nil)
75
+ end
76
+ end
77
+ end
78
+ describe "finding the latest production version" do
79
+ context "when a pact is found" do
80
+ before do
81
+ pact_broker.
82
+ given("a pact between Condor and the Pricing Service exists for the production version of Condor").
83
+ upon_receiving("a request to retrieve the pact between the production verison of Condor and the Pricing Service").
84
+ with(
85
+ method: :get,
86
+ path: '/pact/provider/Pricing%20Service/consumer/Condor/latest/prod',
87
+ headers: get_request_headers
88
+ ).
89
+ will_respond_with(
90
+ status: 200,
91
+ headers: {'Content-Type' => 'application/json', 'X-Pact-Consumer-Version' => consumer_version},
92
+ body: pact_hash,
93
+ headers: pact_broker_response_headers
94
+ )
95
+ end
96
+
97
+ it "returns the pact json" do
98
+ response = pact_broker_client.pacticipants.versions.pacts.latest consumer: 'Condor', provider: 'Pricing Service', tag: 'prod'
99
+ expect(response).to eq(pact_json)
100
+ end
101
+ end
102
+ end
103
+ end
104
+
105
+ describe "retriving versions" do
106
+ context "when retrieving the production details of a version" do
107
+ context "when a version is found" do
108
+ let(:repository_ref) { "package/pricing-service-1.2.3"}
109
+ let(:tags) { ['prod']}
110
+ let(:body) { { number: '1.2.3', repository_ref: repository_ref, tags: tags } }
111
+ before do
112
+ pact_broker.
113
+ given("a version with production details exists for the Pricing Service").
114
+ upon_receiving("a request for the latest version tagged with 'prod'").
115
+ with(
116
+ method: :get,
117
+ path: '/pacticipants/Pricing%20Service/versions/latest',
118
+ query: 'tag=prod',
119
+ headers: get_request_headers).
120
+ will_respond_with(
121
+ status: 200,
122
+ headers: pact_broker_response_headers.merge({'Content-Type' => 'application/json'}),
123
+ body: body )
124
+ end
125
+ it 'returns the version details' do
126
+ expect( pact_broker_client.pacticipants.versions.latest pacticipant: 'Pricing Service', tag: 'prod' ).to eq body
127
+ end
128
+ end
129
+ end
130
+ context "when a version is not found" do
131
+ before do
132
+ pact_broker.
133
+ given("no version exists for the Pricing Service").
134
+ upon_receiving("a request for the latest version").
135
+ with(
136
+ method: :get,
137
+ path: '/pacticipants/Pricing%20Service/versions/latest',
138
+ headers: get_request_headers).
139
+ will_respond_with(
140
+ status: 404,
141
+ headers: pact_broker_response_headers )
142
+ end
143
+ it 'returns nil' do
144
+ expect( pact_broker_client.pacticipants.versions.latest pacticipant: 'Pricing Service' ).to eq nil
145
+ end
146
+ end
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,101 @@
1
+ require 'spec_helper'
2
+ require 'pact_broker/client'
3
+ require_relative 'pact_helper'
4
+
5
+ describe PactBroker::Client::Versions, pact: true do
6
+
7
+ include_context "pact broker"
8
+
9
+ describe "tagging a version with prod details" do
10
+ let(:repository_ref) { "packages/condor-#{version}" }
11
+
12
+ let(:tag_options) { {pacticipant: 'Condor', version: version, repository_ref: repository_ref, :tag => 'prod'} }
13
+ context "when the component exists" do
14
+ before do
15
+ pact_broker.
16
+ given("'Condor' exists in the pact-broker").
17
+ upon_receiving("a request to tag the production version of Condor").
18
+ with(
19
+ method: :put,
20
+ path: '/pacticipants/Condor/versions/1.3.0/tags/prod',
21
+ headers: default_request_headers).
22
+ will_respond_with(
23
+ status: 201,
24
+ headers: pact_broker_response_headers,
25
+ body: {
26
+ _links: {
27
+ self: {
28
+ href:
29
+ Pact::Term.new(
30
+ generate: 'http://localhost:1234/pacticipants/Condor/versions/1.3.0/tags/prod',
31
+ matcher: %r{http://.*/pacticipants/Condor/versions/1.3.0/tags/prod})
32
+ }
33
+ }
34
+ }
35
+ )
36
+ end
37
+ it "returns true" do
38
+ expect(pact_broker_client.pacticipants.versions.tag tag_options).to be_true
39
+ end
40
+ end
41
+ context "when the component does not exist" do
42
+ before do
43
+ pact_broker.
44
+ given("'Condor' does not exist in the pact-broker").
45
+ upon_receiving("a request to tag the production version of Condor").
46
+ with(
47
+ method: :put,
48
+ path: '/pacticipants/Condor/versions/1.3.0/tags/prod',
49
+ headers: default_request_headers).
50
+ will_respond_with(
51
+ status: 201,
52
+ headers: pact_broker_response_headers,
53
+ body: {
54
+ _links: {
55
+ self: {
56
+ href:
57
+ Pact::Term.new(
58
+ generate: 'http://localhost:1234/pacticipants/Condor/versions/1.3.0/tags/prod',
59
+ matcher: %r{http://.*/pacticipants/Condor/versions/1.3.0/tags/prod})
60
+ }
61
+ }
62
+ }
63
+ )
64
+ end
65
+ it "returns true" do
66
+ expect(pact_broker_client.pacticipants.versions.tag tag_options).to be_true
67
+ end
68
+ end
69
+
70
+ context "when the tag already exists" do
71
+ before do
72
+ pact_broker.
73
+ given("'Condor' exists in the pact-broker with version 1.3.0, tagged with 'prod'").
74
+ upon_receiving("a request to tag the production version of Condor").
75
+ with(
76
+ method: :put,
77
+ path: '/pacticipants/Condor/versions/1.3.0/tags/prod',
78
+ headers: default_request_headers).
79
+ will_respond_with(
80
+ status: 200,
81
+ headers: pact_broker_response_headers,
82
+ body: {
83
+ _links: {
84
+ self: {
85
+ href:
86
+ Pact::Term.new(
87
+ generate: 'http://localhost:1234/pacticipants/Condor/versions/1.3.0/tags/prod',
88
+ matcher: %r{http://.*/pacticipants/Condor/versions/1.3.0/tags/prod})
89
+ }
90
+ }
91
+ }
92
+ )
93
+ end
94
+
95
+ it "returns true" do
96
+ expect(pact_broker_client.pacticipants.versions.tag tag_options).to be_true
97
+ end
98
+ end
99
+ end
100
+
101
+ end
data/spec/spec_helper.rb CHANGED
@@ -4,9 +4,4 @@ RSpec.configure do | config |
4
4
  config.include RSpec::Fire
5
5
  end
6
6
 
7
- def silence_warnings
8
- old_verbose, $VERBOSE = $VERBOSE, nil
9
- yield
10
- ensure
11
- $VERBOSE = old_verbose
12
- end
7
+ require "./spec/support/shared_context.rb"
@@ -7,9 +7,11 @@
7
7
  "pacts": [
8
8
  {
9
9
  "_links": {
10
- "self": {
10
+ "self": [{
11
+ "href": "http://example.org/pact/provider/Pricing%20Service/consumer/Condor/latest"
12
+ },{
11
13
  "href": "http://example.org/pact/provider/Pricing%20Service/consumer/Condor/version/1.3.0"
12
- }
14
+ }]
13
15
  },
14
16
  "_embedded": {
15
17
  "consumer": {
@@ -0,0 +1,15 @@
1
+ shared_context "pact broker" do
2
+
3
+ let(:pact_hash) { {consumer: {name: 'Condor'}, provider: {name: 'Pricing Service'}, interactions: []} }
4
+ let(:consumer_contract) { Pact::ConsumerContract.from_hash pact_hash }
5
+ let(:pact_json) { pact_hash.to_json }
6
+ let(:pact_broker_client) { PactBroker::Client::PactBrokerClient.new(base_url: 'http://localhost:1234') }
7
+ let(:consumer_version) { '1.3.0' }
8
+ let(:version) { '1.3.0' }
9
+ let(:pact_broker_version) { Pact::Term.new(:matcher => /\d+\.\d+\.\d+/, :generate => '1.0.0') }
10
+ let(:pact_broker_response_headers) { {} }
11
+ let(:default_request_headers) { { 'Content-Type' => 'application/json'} }
12
+ let(:patch_request_headers) { { 'Content-Type' => 'application/json'} }
13
+ let(:get_request_headers) { { 'Accept' => 'application/json'} }
14
+
15
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pact_broker-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-01-15 00:00:00.000000000 Z
12
+ date: 2014-03-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pact
@@ -155,12 +155,16 @@ files:
155
155
  - spec/lib/pact_broker/client/tasks/publication_task_spec.rb
156
156
  - spec/pacts/pact_broker_client-pact_broker.json
157
157
  - spec/service_providers/extra_goodies_spec.rb
158
- - spec/service_providers/pact_broker_client_spec.rb
158
+ - spec/service_providers/pact_broker_client_publish_spec.rb
159
+ - spec/service_providers/pact_broker_client_register_repository_spec.rb
160
+ - spec/service_providers/pact_broker_client_retrive_pact_spec.rb
161
+ - spec/service_providers/pact_broker_client_tags_spec.rb
159
162
  - spec/service_providers/pact_helper.rb
160
163
  - spec/spec_helper.rb
161
164
  - spec/support/pacticipant_get.json
162
165
  - spec/support/pacticipants_list.json
163
166
  - spec/support/pacts_latest_list.json
167
+ - spec/support/shared_context.rb
164
168
  - tasks/pact.rake
165
169
  homepage: https://github.com/bethesque/pact_broker-client.git
166
170
  licenses:
@@ -177,7 +181,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
177
181
  version: '0'
178
182
  segments:
179
183
  - 0
180
- hash: -1305860573935195556
184
+ hash: -3052204763703773771
181
185
  required_rubygems_version: !ruby/object:Gem::Requirement
182
186
  none: false
183
187
  requirements:
@@ -186,7 +190,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
186
190
  version: '0'
187
191
  segments:
188
192
  - 0
189
- hash: -1305860573935195556
193
+ hash: -3052204763703773771
190
194
  requirements: []
191
195
  rubyforge_project:
192
196
  rubygems_version: 1.8.23
@@ -199,9 +203,13 @@ test_files:
199
203
  - spec/lib/pact_broker/client/tasks/publication_task_spec.rb
200
204
  - spec/pacts/pact_broker_client-pact_broker.json
201
205
  - spec/service_providers/extra_goodies_spec.rb
202
- - spec/service_providers/pact_broker_client_spec.rb
206
+ - spec/service_providers/pact_broker_client_publish_spec.rb
207
+ - spec/service_providers/pact_broker_client_register_repository_spec.rb
208
+ - spec/service_providers/pact_broker_client_retrive_pact_spec.rb
209
+ - spec/service_providers/pact_broker_client_tags_spec.rb
203
210
  - spec/service_providers/pact_helper.rb
204
211
  - spec/spec_helper.rb
205
212
  - spec/support/pacticipant_get.json
206
213
  - spec/support/pacticipants_list.json
207
214
  - spec/support/pacts_latest_list.json
215
+ - spec/support/shared_context.rb
@@ -1,338 +0,0 @@
1
- require_relative 'pact_helper'
2
- require 'pact_broker/client'
3
-
4
- module PactBroker::Client
5
- describe PactBrokerClient, :pact => true do
6
-
7
- before do
8
- @backup_version = PactBroker::Client::VERSION
9
- silence_warnings do
10
- PactBroker::Client::VERSION = "2.0.0"
11
- end
12
- end
13
-
14
- after do
15
- silence_warnings do
16
- PactBroker::Client::VERSION = @backup_version
17
- end
18
- end
19
-
20
- let(:pact_hash) { {consumer: {name: 'Condor'}, provider: {name: 'Pricing Service'}, interactions: []} }
21
- let(:consumer_contract) { Pact::ConsumerContract.from_hash pact_hash }
22
- let(:pact_json) { pact_hash.to_json }
23
- let(:pact_broker_client) { PactBrokerClient.new(base_url: 'http://localhost:1234') }
24
- let(:consumer_version) { '1.3.0' }
25
- let(:version) { '1.3.0' }
26
- let(:pact_broker_version) { Pact::Term.new(:matcher => /\d+\.\d+\.\d+/, :generate => '1.0.0') }
27
- let(:pact_broker_response_headers) { {} }
28
- let(:default_request_headers) { { 'Content-Type' => 'application/json'} }
29
- let(:patch_request_headers) { { 'Content-Type' => 'application/json'} }
30
- let(:get_request_headers) { { 'Accept' => 'application/json'} }
31
-
32
- describe "publishing a pact" do
33
-
34
- let(:options) { { pact_json: pact_json, consumer_version: consumer_version }}
35
-
36
- context "when the provider already exists in the pact-broker" do
37
- before do
38
- pact_broker.
39
- given("the 'Pricing Service' already exists in the pact-broker").
40
- upon_receiving("a request to publish a pact").
41
- with({
42
- method: :put,
43
- path: '/pact/provider/Pricing%20Service/consumer/Condor/version/1.3.0',
44
- headers: default_request_headers,
45
- body: pact_hash }).
46
- will_respond_with( headers: pact_broker_response_headers,
47
- status: 201
48
- )
49
- end
50
- it "returns true" do
51
- expect(pact_broker_client.pacticipants.versions.pacts.publish(options)).to be_true
52
- end
53
- end
54
-
55
- context "when the provider, consumer, pact and version already exist in the pact-broker" do
56
- before do
57
- pact_broker.
58
- given("the 'Pricing Service' and 'Condor' already exist in the pact-broker, and Condor already has a pact published for version 1.3.0").
59
- upon_receiving("a request to publish a pact").
60
- with({
61
- method: :put,
62
- path: '/pact/provider/Pricing%20Service/consumer/Condor/version/1.3.0',
63
- headers: default_request_headers,
64
- body: pact_hash }).
65
- will_respond_with( headers: pact_broker_response_headers,
66
- status: 200
67
- )
68
- end
69
- it "returns true" do
70
- expect(pact_broker_client.pacticipants.versions.pacts.publish(options)).to be_true
71
- end
72
- end
73
-
74
- context "when the provider does not exist, but the consumer, pact and version already exist in the pact-broker" do
75
- before do
76
- pact_broker.
77
- given("'Condor' already exist in the pact-broker, but the 'Pricing Service' does not").
78
- upon_receiving("a request to publish a pact").
79
- with({
80
- method: :put,
81
- path: '/pact/provider/Pricing%20Service/consumer/Condor/version/1.3.0',
82
- headers: default_request_headers,
83
- body: pact_hash }).
84
- will_respond_with( headers: pact_broker_response_headers,
85
- status: 201
86
- )
87
- end
88
- it "returns true" do
89
- expect(pact_broker_client.pacticipants.versions.pacts.publish(options)).to be_true
90
- end
91
- end
92
-
93
- context "when publishing is not successful" do
94
- before do
95
- pact_broker.
96
- given("an error occurs while publishing a pact").
97
- upon_receiving("a request to publish a pact").
98
- with({
99
- method: :put,
100
- path: '/pact/provider/Pricing%20Service/consumer/Condor/version/1.3.0',
101
- headers: default_request_headers,
102
- body: pact_hash }).
103
- will_respond_with({
104
- status: 500,
105
- headers: {'Content-Type' => 'application/json'},
106
- body: {
107
- message: Pact::Term.new(matcher: /.*/, generate: 'An error occurred')
108
- }
109
- })
110
- end
111
- it "raises an error" do
112
- expect { pact_broker_client.pacticipants.versions.pacts.publish options }.to raise_error /An error occurred/
113
- end
114
- end
115
-
116
- end
117
-
118
- let(:repository_url ) { "git@git.realestate.com.au:business-systems/pricing-service" }
119
-
120
- describe "registering a repository url" do
121
- context "where the pacticipant does not already exist in the pact-broker" do
122
- before do
123
- pact_broker.
124
- given("the 'Pricing Service' does not exist in the pact-broker").
125
- upon_receiving("a request to register the repository URL of a pacticipant").
126
- with(
127
- method: :patch,
128
- path: '/pacticipants/Pricing%20Service',
129
- headers: patch_request_headers,
130
- body: {repository_url: repository_url} ).
131
- will_respond_with(
132
- status: 201,
133
- headers: pact_broker_response_headers
134
- )
135
- end
136
- it "returns true" do
137
- expect(pact_broker_client.pacticipants.update({:pacticipant => 'Pricing Service', :repository_url => repository_url})).to be_true
138
- end
139
- end
140
- context "where the 'Pricing Service' exists in the pact-broker" do
141
- before do
142
- pact_broker.
143
- given("the 'Pricing Service' already exists in the pact-broker").
144
- upon_receiving("a request to register the repository URL of a pacticipant").
145
- with(
146
- method: :patch,
147
- path: '/pacticipants/Pricing%20Service',
148
- headers: patch_request_headers,
149
- body: {repository_url: repository_url} ).
150
- will_respond_with(
151
- status: 200,
152
- headers: pact_broker_response_headers
153
- )
154
- end
155
- it "returns true" do
156
- expect(pact_broker_client.pacticipants.update({:pacticipant => 'Pricing Service', :repository_url => repository_url})).to be_true
157
- end
158
- end
159
- end
160
-
161
- describe "tagging a version with prod details" do
162
- let(:repository_ref) { "packages/condor-#{version}" }
163
-
164
- let(:tag_options) { {pacticipant: 'Condor', version: version, repository_ref: repository_ref, :tag => 'prod'} }
165
- context "when the component exists" do
166
- before do
167
- pact_broker.
168
- given("'Condor' exists in the pact-broker").
169
- upon_receiving("a request to tag the production version of Condor").
170
- with(
171
- method: :patch,
172
- path: '/pacticipants/Condor/versions/1.3.0',
173
- headers: patch_request_headers,
174
- body: {:tags => ['prod'], :repository_ref => repository_ref } ).
175
- will_respond_with(
176
- status: 200,
177
- headers: pact_broker_response_headers
178
- )
179
- end
180
- it "returns true" do
181
- expect(pact_broker_client.pacticipants.versions.update tag_options).to be_true
182
- end
183
- end
184
- context "when the component does not exist" do
185
- before do
186
- pact_broker.
187
- given("'Condor' does not exist in the pact-broker").
188
- upon_receiving("a request to tag the production version of Condor").
189
- with(
190
- method: :patch,
191
- path: '/pacticipants/Condor/versions/1.3.0',
192
- headers: patch_request_headers,
193
- body: {:tags => ['prod'], :repository_ref => repository_ref } ).
194
- will_respond_with(
195
- status: 201,
196
- headers: pact_broker_response_headers
197
- )
198
- end
199
- it "returns true" do
200
- expect(pact_broker_client.pacticipants.versions.update tag_options).to be_true
201
- end
202
- end
203
- end
204
-
205
- describe "retrieving a pact" do
206
- describe "retriving a specific version" do
207
- before do
208
- pact_broker.
209
- given("the 'Pricing Service' and 'Condor' already exist in the pact-broker, and Condor already has a pact published for version 1.3.0").
210
- upon_receiving("a request retrieve a pact for a specific version").
211
- with(
212
- method: :get,
213
- path: '/pact/provider/Pricing%20Service/consumer/Condor/version/1.3.0',
214
- headers: {} ).
215
- will_respond_with( headers: pact_broker_response_headers,
216
- status: 200,
217
- body: pact_hash
218
- )
219
- end
220
- it "returns the pact json" do
221
- response = pact_broker_client.pacticipants.versions.pacts.get consumer: 'Condor', provider: 'Pricing Service', consumer_version: '1.3.0'
222
- expect(response).to eq(pact_json)
223
- end
224
- end
225
-
226
- describe "finding the latest version" do
227
- context "when a pact is found" do
228
-
229
- let(:response_headers) { pact_broker_response_headers.merge({'Content-Type' => 'application/json', 'X-Pact-Consumer-Version' => consumer_version}) }
230
- before do
231
- pact_broker.
232
- given("a pact between Condor and the Pricing Service exists").
233
- upon_receiving("a request to retrieve the latest pact between Condor and the Pricing Service").
234
- with({
235
- method: :get,
236
- path: '/pact/provider/Pricing%20Service/consumer/Condor/latest',
237
- headers: {}
238
- }).
239
- will_respond_with({
240
- status: 200,
241
- headers: response_headers,
242
- body: pact_hash
243
- })
244
- end
245
-
246
- it "returns the pact json" do
247
- response = pact_broker_client.pacticipants.versions.pacts.latest consumer: 'Condor', provider: 'Pricing Service'
248
- expect(response).to eq(pact_json)
249
- end
250
-
251
- end
252
- context "when no pact is found" do
253
- before do
254
- pact_broker.
255
- given("no pact between Condor and the Pricing Service exists").
256
- upon_receiving("a request to retrieve the latest pact between Condor and the Pricing Service").
257
- with({
258
- method: :get,
259
- path: '/pact/provider/Pricing%20Service/consumer/Condor/latest',
260
- headers: {}
261
- }).
262
- will_respond_with({
263
- status: 404,
264
- headers: pact_broker_response_headers
265
- })
266
- end
267
- it "returns nil" do
268
- response = pact_broker_client.pacticipants.versions.pacts.latest consumer: 'Condor', provider: 'Pricing Service'
269
- expect(response).to eq(nil)
270
- end
271
- end
272
- end
273
- describe "finding the latest production version" do
274
- context "when a pact is found" do
275
- before do
276
- pact_broker.
277
- given("a pact between Condor and the Pricing Service exists for the production version of Condor").
278
- upon_receiving("a request to retrieve the pact between the production verison of Condor and the Pricing Service").
279
- with({
280
- method: :get,
281
- path: '/pact/provider/Pricing%20Service/consumer/Condor/latest/prod',
282
- headers: get_request_headers
283
- }).
284
- will_respond_with({
285
- status: 200,
286
- headers: {'Content-Type' => 'application/json', 'X-Pact-Consumer-Version' => consumer_version},
287
- body: pact_hash,
288
- headers: pact_broker_response_headers
289
- })
290
- end
291
-
292
- it "returns the pact json" do
293
- response = pact_broker_client.pacticipants.versions.pacts.latest consumer: 'Condor', provider: 'Pricing Service', tag: 'prod'
294
- expect(response).to eq(pact_json)
295
- end
296
- end
297
- end
298
- end
299
-
300
- describe "retriving versions" do
301
- context "when retrieving the production details of a version" do
302
- context "when a version is found" do
303
- let(:repository_ref) { "package/pricing-service-1.2.3"}
304
- let(:tags) { ['prod']}
305
- let(:body) { { number: '1.2.3', repository_ref: repository_ref, tags: tags } }
306
- before do
307
- pact_broker.
308
- given("a version with production details exists for the Pricing Service").
309
- upon_receiving("a request for the latest version tagged with 'prod'").
310
- with(
311
- method: :get,
312
- path: '/pacticipants/Pricing%20Service/versions/latest',
313
- query: 'tag=prod',
314
- headers: get_request_headers).
315
- will_respond_with( status: 200,
316
- headers: pact_broker_response_headers.merge({'Content-Type' => 'application/json'}),
317
- body: body )
318
- end
319
- it 'returns the version details' do
320
- expect( pact_broker_client.pacticipants.versions.latest pacticipant: 'Pricing Service', tag: 'prod' ).to eq body
321
- end
322
- end
323
- end
324
- context "when a version is not found" do
325
- before do
326
- pact_broker.
327
- given("no version exists for the Pricing Service").
328
- upon_receiving("a request for the latest version").
329
- with(method: :get, path: '/pacticipants/Pricing%20Service/versions/latest', headers: get_request_headers).
330
- will_respond_with( status: 404, headers: pact_broker_response_headers )
331
- end
332
- it 'returns nil' do
333
- expect( pact_broker_client.pacticipants.versions.latest pacticipant: 'Pricing Service' ).to eq nil
334
- end
335
- end
336
- end
337
- end
338
- end