pact_broker-client 1.6.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -1
  3. data/CHANGELOG.md +17 -0
  4. data/README.md +2 -1
  5. data/bin/pact-broker +4 -0
  6. data/gemfiles/default.gemfile.lock +29 -24
  7. data/gemfiles/ruby_under_22.gemfile.lock +25 -22
  8. data/lib/pact_broker/client/base_client.rb +16 -1
  9. data/lib/pact_broker/client/can_i_deploy.rb +80 -0
  10. data/lib/pact_broker/client/cli/broker.rb +52 -0
  11. data/lib/pact_broker/client/cli/publish.rb +9 -7
  12. data/lib/pact_broker/client/cli/version_selector_options_parser.rb +29 -0
  13. data/lib/pact_broker/client/matrix.rb +39 -0
  14. data/lib/pact_broker/client/matrix/formatter.rb +20 -0
  15. data/lib/pact_broker/client/matrix/json_formatter.rb +13 -0
  16. data/lib/pact_broker/client/matrix/text_formatter.rb +33 -0
  17. data/lib/pact_broker/client/pact_broker_client.rb +5 -5
  18. data/lib/pact_broker/client/retry.rb +15 -4
  19. data/lib/pact_broker/client/version.rb +1 -1
  20. data/pact-broker-client.gemspec +2 -2
  21. data/spec/lib/pact_broker/client/can_i_deploy_spec.rb +85 -0
  22. data/spec/lib/pact_broker/client/cli/broker_spec.rb +81 -0
  23. data/spec/lib/pact_broker/client/cli/publish_spec.rb +6 -4
  24. data/spec/lib/pact_broker/client/cli/version_selector_options_parser_spec.rb +43 -0
  25. data/spec/lib/pact_broker/client/matrix/text_formatter_spec.rb +29 -0
  26. data/spec/lib/pact_broker/client/matrix_spec.rb +16 -0
  27. data/spec/pacts/pact_broker_client-pact_broker.json +83 -0
  28. data/spec/service_providers/pact_broker_client_matrix_spec.rb +119 -0
  29. data/spec/spec_helper.rb +0 -5
  30. data/spec/support/matrix.json +23 -0
  31. data/spec/support/matrix.txt +3 -0
  32. data/spec/support/matrix_error.txt +3 -0
  33. metadata +50 -23
@@ -0,0 +1,43 @@
1
+ require 'pact_broker/client/cli/version_selector_options_parser'
2
+
3
+ module PactBroker
4
+ module Client
5
+ module CLI
6
+ describe VersionSelectorOptionsParser do
7
+
8
+ TEST_CASES = [
9
+ [
10
+ ["--name", "Foo", "--version", "1.2.3"],
11
+ [{ name: "Foo", version: "1.2.3" } ]
12
+ ],[
13
+ ["-n", "Foo", "-a", "1.2.3"],
14
+ [{ name: "Foo", version: "1.2.3" } ]
15
+ ],[
16
+ ["--name", "Foo"],
17
+ [{ name: "Foo" } ]
18
+ ],[
19
+ ["--name", "Foo", "Bar"],
20
+ [{ name: "Bar" } ]
21
+ ],[
22
+ ["--name", "Foo", "--name", "Bar", "--version", "1.2.3"],
23
+ [{ name: "Foo" }, { name: "Bar", version: "1.2.3" } ]
24
+ ],[
25
+ ["--name", "Foo", "--wrong", "Bar", "--version", "1.2.3"],
26
+ [{ name: "Foo", version: "1.2.3" } ]
27
+ ],[
28
+ ["--name", "the-thing", "--version", "1.2.3"],
29
+ [{ name: "the-thing", version: "1.2.3" } ]
30
+ ]
31
+ ]
32
+
33
+ TEST_CASES.each do | input, output |
34
+
35
+ it "parses #{input.join(' ')}" do
36
+ expect(VersionSelectorOptionsParser.call(input)).to eq output
37
+ end
38
+
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,29 @@
1
+ require 'pact_broker/client/matrix/text_formatter'
2
+
3
+ module PactBroker
4
+ module Client
5
+ describe Matrix::TextFormatter do
6
+ let(:matrix_lines) { JSON.parse(File.read('spec/support/matrix.json'), symbolize_names: true) }
7
+ let(:expected_matrix_lines) { File.read('spec/support/matrix.txt') }
8
+
9
+ # SublimeText removes whitespace from the end of files when you save them,
10
+ # so removing trailing whitespace before comparing
11
+ subject { Matrix::TextFormatter.call(matrix_lines).split("\n").collect(&:strip).join("\n") }
12
+
13
+ context "with valid data" do
14
+ it "it has the right text" do
15
+ expect(subject).to eq expected_matrix_lines
16
+ end
17
+ end
18
+
19
+ context "with invalid data" do
20
+ let(:expected_matrix_lines) { File.read('spec/support/matrix_error.txt') }
21
+ let(:matrix_lines) { [{}] }
22
+
23
+ it "doesn't blow up" do
24
+ expect(subject).to eq expected_matrix_lines
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,16 @@
1
+ require 'pact_broker/client/matrix'
2
+
3
+ module PactBroker
4
+ module Client
5
+ describe Matrix do
6
+ context "when the matrix resource is not found because the broker is the wrong version" do
7
+ let(:matrix) { Matrix.new(base_url: 'http://example.org') }
8
+ let!(:request) { stub_request(:get, /matrix/).to_return(status: 404) }
9
+
10
+ it "raises a helpful error" do
11
+ expect { matrix.get([{name: "Foo", version: "1"}]) }.to raise_error PactBroker::Client::Error, %r{Matrix resource not found at http://example.org/matrix}
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -198,6 +198,89 @@
198
198
  }
199
199
  }
200
200
  },
201
+ {
202
+ "description": "a request for the compatibility matrix for Foo version 1.2.3 and Bar version 4.5.6",
203
+ "providerState": "the pact for Foo version 1.2.3 has been verified by Bar version 4.5.6",
204
+ "request": {
205
+ "method": "get",
206
+ "path": "/matrix",
207
+ "query": "selectors[]=Foo%2Fversion%2F1.2.3&selectors[]=Bar%2Fversion%2F4.5.6"
208
+ },
209
+ "response": {
210
+ "status": 200,
211
+ "headers": {
212
+ },
213
+ "body": {
214
+ "matrix": {
215
+ "json_class": "Pact::SomethingLike",
216
+ "contents": [
217
+ {
218
+ "consumer": {
219
+ "name": "Foo",
220
+ "version": {
221
+ "number": "4"
222
+ }
223
+ },
224
+ "provider": {
225
+ "name": "Bar",
226
+ "version": {
227
+ "number": "5"
228
+ }
229
+ },
230
+ "verificationResult": {
231
+ "verifiedAt": "2017-10-10T12:49:04+11:00",
232
+ "success": true
233
+ },
234
+ "pact": {
235
+ "createdAt": "2017-10-10T12:49:04+11:00"
236
+ }
237
+ }
238
+ ]
239
+ }
240
+ }
241
+ }
242
+ },
243
+ {
244
+ "description": "a request for the compatibility matrix where one or more versions does not exist",
245
+ "providerState": "the pact for Foo version 1.2.3 has been verified by Bar version 4.5.6",
246
+ "request": {
247
+ "method": "get",
248
+ "path": "/matrix",
249
+ "query": "selectors[]=Foo%2Fversion%2F1.2.3&selectors[]=Bar%2Fversion%2F9.9.9"
250
+ },
251
+ "response": {
252
+ "status": 400,
253
+ "headers": {
254
+ },
255
+ "body": {
256
+ "errors": {
257
+ "json_class": "Pact::ArrayLike",
258
+ "contents": "an error message",
259
+ "min": 1
260
+ }
261
+ }
262
+ }
263
+ },
264
+ {
265
+ "description": "a request for the compatibility matrix for a pacticipant that does not exist",
266
+ "request": {
267
+ "method": "get",
268
+ "path": "/matrix",
269
+ "query": "selectors[]=Foo%2Fversion%2F1.2.3&selectors[]=Bar%2Fversion%2F9.9.9"
270
+ },
271
+ "response": {
272
+ "status": 400,
273
+ "headers": {
274
+ },
275
+ "body": {
276
+ "errors": {
277
+ "json_class": "Pact::ArrayLike",
278
+ "contents": "an error message",
279
+ "min": 1
280
+ }
281
+ }
282
+ }
283
+ },
201
284
  {
202
285
  "description": "a request to publish a pact",
203
286
  "providerState": "the 'Pricing Service' already exists in the pact-broker",
@@ -0,0 +1,119 @@
1
+ require_relative 'pact_helper'
2
+ require 'pact_broker/client'
3
+
4
+ module PactBroker::Client
5
+ describe Matrix, :pact => true do
6
+
7
+ include_context "pact broker"
8
+
9
+ describe "retriving the compatibility matrix" do
10
+ let(:matrix_response_body) { { matrix: Pact.like(matrix) } }
11
+ let(:matrix) { JSON.parse(File.read('spec/support/matrix.json')) }
12
+ let(:selectors) { [{ name: "Foo", version: "1.2.3" }, { name: "Bar", version: "4.5.6" }] }
13
+
14
+ context "when results are found" do
15
+ before do
16
+ pact_broker.
17
+ given("the pact for Foo version 1.2.3 has been verified by Bar version 4.5.6").
18
+ upon_receiving("a request for the compatibility matrix for Foo version 1.2.3 and Bar version 4.5.6").
19
+ with(
20
+ method: :get,
21
+ path: "/matrix",
22
+ query: {
23
+ 'selectors[]' => ['Foo/version/1.2.3', 'Bar/version/4.5.6']
24
+ }
25
+ ).
26
+ will_respond_with(
27
+ status: 200,
28
+ headers: pact_broker_response_headers,
29
+ body: matrix_response_body
30
+ )
31
+ end
32
+
33
+ it 'a matrix of compatible versions' do
34
+ matrix = pact_broker_client.matrix.get(selectors)
35
+ expect(matrix.size).to eq 1
36
+ end
37
+ end
38
+
39
+ # context "with only one version selector" do
40
+ # before do
41
+ # pact_broker.
42
+ # given("the pact for Foo version 1.2.3 has been verified by Bar version 4.5.6").
43
+ # upon_receiving("a request for the compatibility matrix where only the version of Foo is specified").
44
+ # with(
45
+ # method: :get,
46
+ # path: "/matrix",
47
+ # query: {
48
+ # 'selectors[]' => ['Foo/version/1.2.3']
49
+ # }
50
+ # ).
51
+ # will_respond_with(
52
+ # status: 200,
53
+ # headers: pact_broker_response_headers,
54
+ # body: matrix_response_body
55
+ # )
56
+ # end
57
+ # end
58
+
59
+ context "when one or more of the versions does not exist" do
60
+ before do
61
+ pact_broker.
62
+ given("the pact for Foo version 1.2.3 has been verified by Bar version 4.5.6").
63
+ upon_receiving("a request for the compatibility matrix where one or more versions does not exist").
64
+ with(
65
+ method: :get,
66
+ path: "/matrix",
67
+ query: {
68
+ 'selectors[]' => ['Foo/version/1.2.3', 'Bar/version/9.9.9']
69
+ }
70
+ ).
71
+ will_respond_with(
72
+ status: 400,
73
+ headers: pact_broker_response_headers,
74
+ body: {
75
+ errors: Pact.each_like("an error message")
76
+ }
77
+ )
78
+ end
79
+
80
+ let(:selectors) { [{ name: "Foo", version: "1.2.3" }, { name: "Bar", version: "9.9.9" }] }
81
+
82
+ it 'returns a list of errors' do
83
+ expect {
84
+ pact_broker_client.matrix.get(selectors)
85
+ }.to raise_error PactBroker::Client::Error, "an error message"
86
+ end
87
+ end
88
+
89
+ context "when results are not found" do
90
+ before do
91
+ pact_broker.
92
+ upon_receiving("a request for the compatibility matrix for a pacticipant that does not exist").
93
+ with(
94
+ method: :get,
95
+ path: "/matrix",
96
+ query: {
97
+ 'selectors[]' => ['Foo/version/1.2.3', 'Bar/version/9.9.9']
98
+ }
99
+ ).
100
+ will_respond_with(
101
+ status: 400,
102
+ headers: pact_broker_response_headers,
103
+ body: {
104
+ errors: Pact.each_like("an error message")
105
+ }
106
+ )
107
+ end
108
+
109
+ let(:selectors) { [{ name: "Foo", version: "1.2.3" }, { name: "Bar", version: "9.9.9" }] }
110
+
111
+ it 'returns a list of errors' do
112
+ expect {
113
+ pact_broker_client.matrix.get(selectors)
114
+ }.to raise_error PactBroker::Client::Error, "an error message"
115
+ end
116
+ end
117
+ end
118
+ end
119
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,10 +1,5 @@
1
- require 'rspec/fire'
2
1
  require 'webmock/rspec'
3
2
 
4
3
  WebMock.disable_net_connect!(allow_localhost: true)
5
4
 
6
- RSpec.configure do | config |
7
- config.include RSpec::Fire
8
- end
9
-
10
5
  require "./spec/support/shared_context.rb"
@@ -0,0 +1,23 @@
1
+ [
2
+ {
3
+ "consumer": {
4
+ "name": "Foo",
5
+ "version": {
6
+ "number": "4"
7
+ }
8
+ },
9
+ "provider": {
10
+ "name": "Bar",
11
+ "version": {
12
+ "number": "5"
13
+ }
14
+ },
15
+ "verificationResult": {
16
+ "verifiedAt": "2017-10-10T12:49:04+11:00",
17
+ "success": true
18
+ },
19
+ "pact": {
20
+ "createdAt": "2017-10-10T12:49:04+11:00"
21
+ }
22
+ }
23
+ ]
@@ -0,0 +1,3 @@
1
+ CONSUMER | CONSUMER_VERSION | PROVIDER | PROVIDER_VERSION | SUCCESS
2
+ ---------|------------------|----------|------------------|--------
3
+ Foo | 4 | Foo | 5 | true
@@ -0,0 +1,3 @@
1
+ CONSUMER | CONSUMER_VERSION | PROVIDER | PROVIDER_VERSION | SUCCESS
2
+ ---------|------------------|----------|------------------|--------
3
+ ??? | ??? | ??? | ??? | ???
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.6.0
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bethany Skurrie
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-01 00:00:00.000000000 Z
11
+ date: 2017-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -53,19 +53,19 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: pry
56
+ name: table_print
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
61
+ version: '1.5'
62
+ type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: '1.5'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: fakefs
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -80,20 +80,6 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0.4'
83
- - !ruby/object:Gem::Dependency
84
- name: rspec-fire
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
83
  - !ruby/object:Gem::Dependency
98
84
  name: appraisal
99
85
  requirement: !ruby/object:Gem::Requirement
@@ -150,10 +136,25 @@ dependencies:
150
136
  - - "~>"
151
137
  - !ruby/object:Gem::Version
152
138
  version: '1.16'
139
+ - !ruby/object:Gem::Dependency
140
+ name: pry-byebug
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
153
  description: Publishes pacts to, and retrieves pacts from, the pact broker server.
154
154
  email:
155
155
  - bskurrie@dius.com.au
156
156
  executables:
157
+ - pact-broker
157
158
  - pact-publish
158
159
  extensions: []
159
160
  extra_rdoc_files: []
@@ -167,6 +168,7 @@ files:
167
168
  - README.md
168
169
  - RELEASING.md
169
170
  - Rakefile
171
+ - bin/pact-broker
170
172
  - bin/pact-publish
171
173
  - ci.sh
172
174
  - doc/markdown/Pact Broker Client - Pact Broker.md
@@ -177,9 +179,16 @@ files:
177
179
  - gemfiles/ruby_under_22.gemfile.lock
178
180
  - lib/pact_broker/client.rb
179
181
  - lib/pact_broker/client/base_client.rb
182
+ - lib/pact_broker/client/can_i_deploy.rb
183
+ - lib/pact_broker/client/cli/broker.rb
180
184
  - lib/pact_broker/client/cli/custom_thor.rb
181
185
  - lib/pact_broker/client/cli/publish.rb
186
+ - lib/pact_broker/client/cli/version_selector_options_parser.rb
182
187
  - lib/pact_broker/client/error.rb
188
+ - lib/pact_broker/client/matrix.rb
189
+ - lib/pact_broker/client/matrix/formatter.rb
190
+ - lib/pact_broker/client/matrix/json_formatter.rb
191
+ - lib/pact_broker/client/matrix/text_formatter.rb
183
192
  - lib/pact_broker/client/merge_pacts.rb
184
193
  - lib/pact_broker/client/pact_broker_client.rb
185
194
  - lib/pact_broker/client/pact_file.rb
@@ -195,8 +204,13 @@ files:
195
204
  - lib/pact_broker_client.rb
196
205
  - pact-broker-client.gemspec
197
206
  - spec/lib/pact_broker/client/base_client_spec.rb
207
+ - spec/lib/pact_broker/client/can_i_deploy_spec.rb
208
+ - spec/lib/pact_broker/client/cli/broker_spec.rb
198
209
  - spec/lib/pact_broker/client/cli/custom_thor_spec.rb
199
210
  - spec/lib/pact_broker/client/cli/publish_spec.rb
211
+ - spec/lib/pact_broker/client/cli/version_selector_options_parser_spec.rb
212
+ - spec/lib/pact_broker/client/matrix/text_formatter_spec.rb
213
+ - spec/lib/pact_broker/client/matrix_spec.rb
200
214
  - spec/lib/pact_broker/client/merge_pacts_spec.rb
201
215
  - spec/lib/pact_broker/client/pact_broker_client_spec.rb
202
216
  - spec/lib/pact_broker/client/pacticipants_spec.rb
@@ -205,6 +219,7 @@ files:
205
219
  - spec/lib/pact_broker/client/versions_spec.rb
206
220
  - spec/pacts/pact_broker_client-pact_broker.json
207
221
  - spec/service_providers/extra_goodies_spec.rb
222
+ - spec/service_providers/pact_broker_client_matrix_spec.rb
208
223
  - spec/service_providers/pact_broker_client_pacticipant_version_spec.rb
209
224
  - spec/service_providers/pact_broker_client_publish_spec.rb
210
225
  - spec/service_providers/pact_broker_client_register_repository_spec.rb
@@ -216,6 +231,9 @@ files:
216
231
  - spec/support/cli_test_pacts/bar.json
217
232
  - spec/support/cli_test_pacts/foo.json
218
233
  - spec/support/latest_pacts_for_provider.json
234
+ - spec/support/matrix.json
235
+ - spec/support/matrix.txt
236
+ - spec/support/matrix_error.txt
219
237
  - spec/support/pacticipant_get.json
220
238
  - spec/support/pacticipants_list.json
221
239
  - spec/support/pacts_latest_list.json
@@ -241,14 +259,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
241
259
  version: '0'
242
260
  requirements: []
243
261
  rubyforge_project:
244
- rubygems_version: 2.6.12
262
+ rubygems_version: 2.6.11
245
263
  signing_key:
246
264
  specification_version: 4
247
265
  summary: See description
248
266
  test_files:
249
267
  - spec/lib/pact_broker/client/base_client_spec.rb
268
+ - spec/lib/pact_broker/client/can_i_deploy_spec.rb
269
+ - spec/lib/pact_broker/client/cli/broker_spec.rb
250
270
  - spec/lib/pact_broker/client/cli/custom_thor_spec.rb
251
271
  - spec/lib/pact_broker/client/cli/publish_spec.rb
272
+ - spec/lib/pact_broker/client/cli/version_selector_options_parser_spec.rb
273
+ - spec/lib/pact_broker/client/matrix/text_formatter_spec.rb
274
+ - spec/lib/pact_broker/client/matrix_spec.rb
252
275
  - spec/lib/pact_broker/client/merge_pacts_spec.rb
253
276
  - spec/lib/pact_broker/client/pact_broker_client_spec.rb
254
277
  - spec/lib/pact_broker/client/pacticipants_spec.rb
@@ -257,6 +280,7 @@ test_files:
257
280
  - spec/lib/pact_broker/client/versions_spec.rb
258
281
  - spec/pacts/pact_broker_client-pact_broker.json
259
282
  - spec/service_providers/extra_goodies_spec.rb
283
+ - spec/service_providers/pact_broker_client_matrix_spec.rb
260
284
  - spec/service_providers/pact_broker_client_pacticipant_version_spec.rb
261
285
  - spec/service_providers/pact_broker_client_publish_spec.rb
262
286
  - spec/service_providers/pact_broker_client_register_repository_spec.rb
@@ -268,6 +292,9 @@ test_files:
268
292
  - spec/support/cli_test_pacts/bar.json
269
293
  - spec/support/cli_test_pacts/foo.json
270
294
  - spec/support/latest_pacts_for_provider.json
295
+ - spec/support/matrix.json
296
+ - spec/support/matrix.txt
297
+ - spec/support/matrix_error.txt
271
298
  - spec/support/pacticipant_get.json
272
299
  - spec/support/pacticipants_list.json
273
300
  - spec/support/pacts_latest_list.json