pact_broker-client 1.31.0 → 1.32.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/lib/pact_broker/client/base_client.rb +11 -9
- data/lib/pact_broker/client/matrix.rb +3 -1
- data/lib/pact_broker/client/pacts/list_latest_versions.rb +1 -1
- data/lib/pact_broker/client/version.rb +1 -1
- data/spec/lib/pact_broker/client/base_client_spec.rb +62 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9fc996a2d95d7c3755d063cd244b273fa5924f6956cf18b26ebe9531fa59e304
|
4
|
+
data.tar.gz: '018d1d764a83f040d57d6ef504a6b4229f34f3fff38cf938c8c3f2202e03cc7a'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95944c92c42aa29803c5bd37b5b4c8526359cb910c4a983123379ac2f0482483aae75fc9179d2e6341e1931019c3f1588e1d7a385ffa628c203fd829d3137bfb
|
7
|
+
data.tar.gz: 5391400fa12118608718161c3ea286ffe1b3b7aebbe1eca074b999b1903b25f6a3f15e257459e35240e30faf768949d45c45a052616378507b0eaf970590ee1b
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
<a name="v1.32.0"></a>
|
2
|
+
### v1.32.0 (2020-10-26)
|
3
|
+
|
4
|
+
#### Features
|
5
|
+
|
6
|
+
* Improve HTTP errors handling (#76) ([d8eaf16](/../../commit/d8eaf16))
|
7
|
+
|
8
|
+
#### Bug Fixes
|
9
|
+
|
10
|
+
* **list-latest-pact-versions**
|
11
|
+
* correct json output ([cf77666](/../../commit/cf77666))
|
12
|
+
|
1
13
|
<a name="v1.31.0"></a>
|
2
14
|
### v1.31.0 (2020-10-22)
|
3
15
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'erb'
|
2
4
|
require 'httparty'
|
3
5
|
require 'pact_broker/client/error'
|
@@ -30,6 +32,12 @@ module PactBroker
|
|
30
32
|
end
|
31
33
|
|
32
34
|
class BaseClient
|
35
|
+
ERROR_CODE_MAPPING = {
|
36
|
+
401 => "Authentication failed",
|
37
|
+
403 => "Authorization failed (insufficient permissions)",
|
38
|
+
409 => "Potential duplicate pacticipants"
|
39
|
+
}.freeze
|
40
|
+
|
33
41
|
include UrlHelpers
|
34
42
|
include HTTParty
|
35
43
|
include StringToSymbol
|
@@ -69,14 +77,8 @@ module PactBroker
|
|
69
77
|
yield response
|
70
78
|
elsif response.code == 404
|
71
79
|
nil
|
72
|
-
elsif response.code
|
73
|
-
message =
|
74
|
-
if response.body && response.body.size > 0
|
75
|
-
message = message + ": #{response.body}"
|
76
|
-
end
|
77
|
-
raise Error.new(message)
|
78
|
-
elsif response.code == 401
|
79
|
-
message = "Authentication failed"
|
80
|
+
elsif ERROR_CODE_MAPPING.key?(response.code)
|
81
|
+
message = ERROR_CODE_MAPPING.fetch(response.code)
|
80
82
|
if response.body && response.body.size > 0
|
81
83
|
message = message + ": #{response.body}"
|
82
84
|
end
|
@@ -93,7 +95,7 @@ module PactBroker
|
|
93
95
|
response.body
|
94
96
|
end
|
95
97
|
rescue
|
96
|
-
raise Error.new(response.body)
|
98
|
+
raise Error.new("status=#{response.code} #{response.body}")
|
97
99
|
end
|
98
100
|
raise Error.new(error_message)
|
99
101
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'base_client'
|
2
4
|
require 'pact_broker/client/matrix/resource'
|
3
5
|
|
@@ -39,7 +41,7 @@ module PactBroker
|
|
39
41
|
response.body
|
40
42
|
end
|
41
43
|
rescue
|
42
|
-
raise Error.new(response.body)
|
44
|
+
raise Error.new("status=#{response.code} #{response.body}")
|
43
45
|
end
|
44
46
|
raise Error.new(error_message)
|
45
47
|
end
|
@@ -2,10 +2,11 @@ require 'pact_broker/client/base_client'
|
|
2
2
|
module PactBroker
|
3
3
|
module Client
|
4
4
|
describe BaseClient do
|
5
|
-
|
6
|
-
|
5
|
+
subject { BaseClient.new(base_url: base_url) }
|
6
|
+
|
7
|
+
let(:base_url) { 'http://pact_broker_base_url'}
|
7
8
|
|
8
|
-
|
9
|
+
describe '#initialize' do
|
9
10
|
let(:username) { 'pact_repo_username'}
|
10
11
|
let(:password) { 'pact_repo_password'}
|
11
12
|
let(:token) { '123456789' }
|
@@ -119,6 +120,63 @@ module PactBroker
|
|
119
120
|
end
|
120
121
|
end
|
121
122
|
end
|
123
|
+
|
124
|
+
describe '#handle_response' do
|
125
|
+
let(:response) { double('Response', success?: true) }
|
126
|
+
|
127
|
+
it 'yields response object' do
|
128
|
+
expect { |block| subject.handle_response(response, &block) }.to yield_with_args(response)
|
129
|
+
end
|
130
|
+
|
131
|
+
context 'with 404 response' do
|
132
|
+
let(:response) { double('Response', success?: false, code: 404) }
|
133
|
+
it 'returns nil' do
|
134
|
+
expect(subject.handle_response(response)).to be_nil
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
context 'with 401 response' do
|
139
|
+
let(:response) { double('Response', success?: false, code: 401, body: 'body') }
|
140
|
+
it 'raise an exception with meaningful message' do
|
141
|
+
expect { subject.handle_response(response) }
|
142
|
+
.to raise_error(PactBroker::Client::Error, "Authentication failed: body")
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
context 'with 403 response' do
|
147
|
+
let(:response) { double('Response', success?: false, code: 403, body: 'body') }
|
148
|
+
it 'raise an exception with meaningful message' do
|
149
|
+
expect { subject.handle_response(response) }
|
150
|
+
.to raise_error(PactBroker::Client::Error, "Authorization failed (insufficient permissions): body")
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
context 'with 409 response' do
|
155
|
+
let(:response) { double('Response', success?: false, code: 409, body: 'body') }
|
156
|
+
it 'raise an exception with meaningful message' do
|
157
|
+
expect { subject.handle_response(response) }
|
158
|
+
.to raise_error(PactBroker::Client::Error, "Potential duplicate pacticipants: body")
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
context 'with unsuccessful JSON response' do
|
163
|
+
let(:response) do
|
164
|
+
double('Response', success?: false, code: 500, body: '{"errors": ["Internal server error"]}')
|
165
|
+
end
|
166
|
+
it 'raise an exception with meaningful message' do
|
167
|
+
expect { subject.handle_response(response) }
|
168
|
+
.to raise_error(PactBroker::Client::Error, "Internal server error")
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
context 'with unsucessful nono-JSON response ' do
|
173
|
+
let(:response) { double('Response', success?: false, code: 500, body: 'Internal server error') }
|
174
|
+
it 'raise an exception with meaningful message' do
|
175
|
+
expect { subject.handle_response(response) }
|
176
|
+
.to raise_error(PactBroker::Client::Error, "status=500 Internal server error")
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
122
180
|
end
|
123
181
|
end
|
124
|
-
end
|
182
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pact_broker-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.32.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Beth Skurrie
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-10-
|
11
|
+
date: 2020-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|