pact_broker-client 1.17.0 → 1.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/README.md +36 -15
- data/lib/pact_broker/client/base_client.rb +1 -0
- data/lib/pact_broker/client/can_i_deploy.rb +8 -3
- data/lib/pact_broker/client/cli/broker.rb +10 -9
- data/lib/pact_broker/client/cli/custom_thor.rb +1 -0
- data/lib/pact_broker/client/matrix/text_formatter.rb +3 -1
- data/lib/pact_broker/client/tasks/publication_task.rb +5 -3
- data/lib/pact_broker/client/version.rb +1 -1
- data/spec/lib/pact_broker/client/base_client_spec.rb +23 -6
- data/spec/lib/pact_broker/client/cli/broker_can_i_deploy_spec.rb +3 -2
- data/spec/lib/pact_broker/client/cli/broker_create_webhook_spec.rb +3 -2
- data/spec/lib/pact_broker/client/cli/broker_publish_spec.rb +1 -1
- data/spec/lib/pact_broker/client/cli/custom_thor_spec.rb +4 -0
- data/spec/lib/pact_broker/client/publish_pacts_spec.rb +5 -3
- data/spec/lib/pact_broker/client/tasks/publication_task_spec.rb +10 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '038d9dad336dd4380cecfed72c8149a0db8b6083'
|
4
|
+
data.tar.gz: 534b53f01fe7d391edadc74e01513a2cb0914c9d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c6a3cd12937059590d1d8e775ff33bbde1d232b9870394e1bd123472c9e27d5ec840463abe9c047deff7d72b152cba9be489ca2fe8eebcc643a137f7e27a96b
|
7
|
+
data.tar.gz: fdc7eaf43f5d2008e8bfa0a04301fef007bf07fa11fde3a9076ab65ab46b6a392a9948055ff1368de20a5384e2642fbac20f2037019fa67088e3ab957aca8812
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
<a name="v1.18.0"></a>
|
2
|
+
### v1.18.0 (2019-03-05)
|
3
|
+
|
4
|
+
|
5
|
+
#### Features
|
6
|
+
|
7
|
+
* remove 'no data' message when there are no rows. ([b0246a2](/../../commit/b0246a2))
|
8
|
+
* allow for broker token to be used ([3266bc1](/../../commit/3266bc1))
|
9
|
+
* add broker token to cli ([e342c29](/../../commit/e342c29))
|
10
|
+
|
11
|
+
|
1
12
|
<a name="v1.17.0"></a>
|
2
13
|
### v1.17.0 (2018-11-15)
|
3
14
|
|
data/README.md
CHANGED
@@ -29,6 +29,7 @@ Options:
|
|
29
29
|
-b, --broker-base-url=BROKER_BASE_URL # The base URL of the Pact Broker
|
30
30
|
-u, [--broker-username=BROKER_USERNAME] # Pact Broker basic auth username
|
31
31
|
-p, [--broker-password=BROKER_PASSWORD] # Pact Broker basic auth password
|
32
|
+
-k, [--broker-token=BROKER_TOKEN] # Pact Broker bearer token
|
32
33
|
-t, [--tag=TAG] # Tag name for consumer version. Can be specified multiple times.
|
33
34
|
-g, [--tag-with-git-branch], [--no-tag-with-git-branch] # Tag consumer version with the name of the current git branch. Default: false
|
34
35
|
-v, [--verbose], [--no-verbose] # Verbose output. Default: false
|
@@ -50,6 +51,7 @@ Options:
|
|
50
51
|
-b, --broker-base-url=BROKER_BASE_URL # The base URL of the Pact Broker
|
51
52
|
-u, [--broker-username=BROKER_USERNAME] # Pact Broker basic auth username
|
52
53
|
-p, [--broker-password=BROKER_PASSWORD] # Pact Broker basic auth password
|
54
|
+
-k, [--broker-token=BROKER_TOKEN] # Pact Broker bearer token
|
53
55
|
-v, [--verbose], [--no-verbose] # Verbose output. Default: false
|
54
56
|
|
55
57
|
Add a tag to a pacticipant version
|
@@ -71,6 +73,7 @@ Options:
|
|
71
73
|
-b, --broker-base-url=BROKER_BASE_URL # The base URL of the Pact Broker
|
72
74
|
-u, [--broker-username=BROKER_USERNAME] # Pact Broker basic auth username
|
73
75
|
-p, [--broker-password=BROKER_PASSWORD] # Pact Broker basic auth password
|
76
|
+
-k, [--broker-token=BROKER_TOKEN] # Pact Broker bearer token
|
74
77
|
-o, [--output=OUTPUT] # json or table
|
75
78
|
# Default: table
|
76
79
|
-v, [--verbose], [--no-verbose] # Verbose output. Default: false
|
@@ -80,51 +83,68 @@ Options:
|
|
80
83
|
# Default: 10
|
81
84
|
|
82
85
|
Description:
|
83
|
-
Returns exit code 0 or 1, indicating whether or not the specified pacticipant versions are compatible. Prints out the relevant
|
86
|
+
Returns exit code 0 or 1, indicating whether or not the specified pacticipant versions are compatible. Prints out the relevant
|
87
|
+
pact/verification details.
|
84
88
|
|
85
|
-
The environment variables PACT_BROKER_BASE_URL,
|
89
|
+
The environment variables PACT_BROKER_BASE_URL, PACT_BROKER_BASE_URL_USERNAME and PACT_BROKER_BASE_URL_PASSWORD may be used
|
90
|
+
instead of their respective command line options.
|
86
91
|
|
87
92
|
SCENARIOS
|
88
93
|
|
89
94
|
# If every build goes straight to production
|
90
95
|
|
91
|
-
Check the status of the pacts for a pacticipant version. Note that this only checks that the most recent verification for each
|
96
|
+
Check the status of the pacts for a pacticipant version. Note that this only checks that the most recent verification for each
|
97
|
+
pact is successful. It doesn't provide any assurance that the pact has been verified by the *production* version of the
|
98
|
+
provider, however, it is sufficient if you are doing true continuous deployment.
|
92
99
|
|
93
|
-
|
100
|
+
$ pact-broker can-i-deploy --pacticipant PACTICIPANT --version VERSION --broker-base-url BROKER_BASE_URL
|
94
101
|
|
95
102
|
# If every build does NOT go straight to production
|
96
103
|
|
97
104
|
## Recommended approach
|
98
105
|
|
99
|
-
If all applications within the pact network are not being deployed continuously (ie. if there is a gap between pact
|
106
|
+
If all applications within the pact network are not being deployed continuously (ie. if there is a gap between pact
|
107
|
+
verification and actual deployment) then the following strategy is recommended. Each application version should be tagged in
|
108
|
+
the broker with the name of the stage (eg. test, staging, production) as it is deployed (see the pact-broker create-version-tag
|
109
|
+
CLI). This enables you to use the following very simple command to check if the application version you are about to deploy is
|
110
|
+
compatible with every other application version already deployed in that environment.
|
100
111
|
|
101
|
-
|
112
|
+
$ pact-broker can-i-deploy --pacticipant PACTICIPANT --version VERSION --to TAG --broker-base-url BROKER_BASE_URL
|
102
113
|
|
103
114
|
## Other approaches
|
104
115
|
|
105
|
-
If you do not/cannot tag every application at deployment, you have two options. You can either use the very first form of this
|
116
|
+
If you do not/cannot tag every application at deployment, you have two options. You can either use the very first form of this
|
117
|
+
command which just checks that the *latest* verification is successful (not recommended as it's the production version that you
|
118
|
+
really care about) or you will need to determine the production versions of each collaborating application from some other
|
119
|
+
source (eg. git) and explictly reference each one using one using the format `--pacticipant PACTICIPANT1 --version VERSION1
|
120
|
+
--pacticipant PACTICIPANT2 --version VERSION2 ...`
|
106
121
|
|
107
122
|
# Other commands
|
108
123
|
|
109
|
-
Check the status of the pacts for the latest pacticipant version. This form is not recommended for use in your CI as it is
|
124
|
+
Check the status of the pacts for the latest pacticipant version. This form is not recommended for use in your CI as it is
|
125
|
+
possible that the version you are about to deploy is not the the version that the Broker considers the latest. It's best to
|
126
|
+
specify the version explictly.
|
110
127
|
|
111
|
-
|
128
|
+
$ pact-broker can-i-deploy --pacticipant PACTICIPANT --latest --broker-base-url BROKER_BASE_URL
|
112
129
|
|
113
130
|
Check the status of the pacts for the latest pacticipant version for a given tag:
|
114
131
|
|
115
|
-
|
132
|
+
$ pact-broker can-i-deploy --pacticipant PACTICIPANT --latest TAG --broker-base-url BROKER_BASE_URL
|
116
133
|
|
117
134
|
Check the status of the pacts between two (or more) specific pacticipant versions:
|
118
135
|
|
119
|
-
|
136
|
+
$ pact-broker can-i-deploy --pacticipant PACTICIPANT1 --version VERSION1 --pacticipant PACTICIPANT2 --version VERSION2
|
137
|
+
--broker-base-url BROKER_BASE_URL
|
120
138
|
|
121
139
|
Check the status of the pacts between the latest versions of two (or more) pacticipants:
|
122
140
|
|
123
|
-
|
141
|
+
$ pact-broker can-i-deploy --pacticipant PACTICIPANT1 --latest --pacticipant PACTICIPANT2 --latest --broker-base-url
|
142
|
+
BROKER_BASE_URL
|
124
143
|
|
125
144
|
Check the status of the pacts between the latest versions of two (or more) pacticipants with a given tag:
|
126
145
|
|
127
|
-
$ pact-broker can-i-deploy --pacticipant PACTICIPANT1 --latest TAG1 --pacticipant PACTICIPANT2 --latest TAG2 --broker-base-url
|
146
|
+
$ pact-broker can-i-deploy --pacticipant PACTICIPANT1 --latest TAG1 --pacticipant PACTICIPANT2 --latest TAG2 --broker-base-url
|
147
|
+
BROKER_BASE_URL
|
128
148
|
|
129
149
|
```
|
130
150
|
|
@@ -167,12 +187,12 @@ Options:
|
|
167
187
|
-b, --broker-base-url=BROKER_BASE_URL # The base URL of the Pact Broker
|
168
188
|
-u, [--broker-username=BROKER_USERNAME] # Pact Broker basic auth username
|
169
189
|
-p, [--broker-password=BROKER_PASSWORD] # Pact Broker basic auth password
|
190
|
+
-k, [--broker-token=BROKER_TOKEN] # Pact Broker bearer token
|
170
191
|
-o, [--output=OUTPUT] # json or table or id
|
171
192
|
# Default: table
|
172
193
|
-v, [--verbose], [--no-verbose] # Verbose output. Default: false
|
173
194
|
|
174
|
-
|
175
|
-
Describes a pacticipant version. If no version or tag is specified, the latest version is described.
|
195
|
+
Describes a pacticipant version. If no version or tag is specified, the latest version is described.
|
176
196
|
```
|
177
197
|
|
178
198
|
## Usage - Ruby
|
@@ -198,6 +218,7 @@ PactBroker::Client::PublicationTask.new do | task |
|
|
198
218
|
task.tag_with_git_branch = true|false # Optional but STRONGLY RECOMMENDED as it will greatly assist with your pact workflow. Result will be merged with other specified task.tags
|
199
219
|
task.tags = ["dev"] # optional
|
200
220
|
task.pact_broker_basic_auth = { username: 'basic_auth_user', password: 'basic_auth_pass'} # optional
|
221
|
+
task.pact_broker_token = "1234abcd" # Bearer token
|
201
222
|
task.write_method = :merge # optional, this will merge the published pact into an existing pact rather than overwriting it if one exists. Not recommended, as it makes a mulch of the workflow on the broker.
|
202
223
|
end
|
203
224
|
```
|
@@ -43,6 +43,7 @@ module PactBroker
|
|
43
43
|
self.class.base_uri base_url
|
44
44
|
self.class.debug_output($stderr) if verbose?
|
45
45
|
self.class.basic_auth(client_options[:basic_auth][:username], client_options[:basic_auth][:password]) if client_options[:basic_auth]
|
46
|
+
self.class.headers('Authorization' => "Bearer #{client_options[:token]}") if client_options[:token]
|
46
47
|
self.class.ssl_ca_file(ENV['SSL_CERT_FILE']) if ENV['SSL_CERT_FILE'] && ENV['SSL_CERT_FILE'] != ''
|
47
48
|
self.class.ssl_ca_path(ENV['SSL_CERT_DIR']) if ENV['SSL_CERT_DIR'] && ENV['SSL_CERT_DIR'] != ''
|
48
49
|
end
|
@@ -52,7 +52,7 @@ module PactBroker
|
|
52
52
|
def success_message(matrix)
|
53
53
|
message = format_matrix(matrix)
|
54
54
|
if format != 'json'
|
55
|
-
message = 'Computer says yes \o/ ' + "\n\n" +
|
55
|
+
message = 'Computer says yes \o/ ' + message + "\n\n" + Term::ANSIColor.green(matrix.reason)
|
56
56
|
end
|
57
57
|
message
|
58
58
|
end
|
@@ -60,13 +60,18 @@ module PactBroker
|
|
60
60
|
def failure_message(matrix)
|
61
61
|
message = format_matrix(matrix)
|
62
62
|
if format != 'json'
|
63
|
-
message = 'Computer says no ¯\_(ツ)_/¯ ' + "\n\n" +
|
63
|
+
message = 'Computer says no ¯\_(ツ)_/¯ ' + message + "\n\n" + Term::ANSIColor.red(matrix.reason)
|
64
64
|
end
|
65
65
|
message
|
66
66
|
end
|
67
67
|
|
68
68
|
def format_matrix(matrix)
|
69
|
-
Matrix::Formatter.call(matrix, format)
|
69
|
+
formatted_matrix = Matrix::Formatter.call(matrix, format)
|
70
|
+
if format != 'json' && formatted_matrix.size > 0
|
71
|
+
"\n\n" + formatted_matrix
|
72
|
+
else
|
73
|
+
formatted_matrix
|
74
|
+
end
|
70
75
|
end
|
71
76
|
|
72
77
|
def format
|
@@ -27,6 +27,7 @@ module PactBroker
|
|
27
27
|
method_option :broker_base_url, required: true, aliases: "-b", desc: "The base URL of the Pact Broker"
|
28
28
|
method_option :broker_username, aliases: "-u", desc: "Pact Broker basic auth username"
|
29
29
|
method_option :broker_password, aliases: "-p", desc: "Pact Broker basic auth password"
|
30
|
+
method_option :broker_token, aliases: "-k", desc: "Pact Broker bearer token"
|
30
31
|
method_option :output, aliases: "-o", desc: "json or table", default: 'table'
|
31
32
|
method_option :verbose, aliases: "-v", type: :boolean, default: false, required: false, desc: "Verbose output. Default: false"
|
32
33
|
method_option :retry_while_unknown, banner: 'TIMES', type: :numeric, default: 0, required: false, desc: "The number of times to retry while there is an unknown verification result (ie. the provider verification is likely still running)"
|
@@ -46,6 +47,7 @@ module PactBroker
|
|
46
47
|
method_option :broker_base_url, required: true, aliases: "-b", desc: "The base URL of the Pact Broker"
|
47
48
|
method_option :broker_username, aliases: "-u", desc: "Pact Broker basic auth username"
|
48
49
|
method_option :broker_password, aliases: "-p", desc: "Pact Broker basic auth password"
|
50
|
+
method_option :broker_token, aliases: "-k", desc: "Pact Broker bearer token"
|
49
51
|
method_option :tag, aliases: "-t", type: :array, banner: "TAG", desc: "Tag name for consumer version. Can be specified multiple times."
|
50
52
|
method_option :tag_with_git_branch, aliases: "-g", type: :boolean, default: false, required: false, desc: "Tag consumer version with the name of the current git branch. Default: false"
|
51
53
|
method_option :verbose, aliases: "-v", type: :boolean, default: false, required: false, desc: "Verbose output. Default: false"
|
@@ -66,6 +68,7 @@ module PactBroker
|
|
66
68
|
method_option :broker_base_url, required: true, aliases: "-b", desc: "The base URL of the Pact Broker"
|
67
69
|
method_option :broker_username, aliases: "-u", desc: "Pact Broker basic auth username"
|
68
70
|
method_option :broker_password, aliases: "-p", desc: "Pact Broker basic auth password"
|
71
|
+
method_option :broker_token, aliases: "-k", desc: "Pact Broker bearer token"
|
69
72
|
method_option :verbose, aliases: "-v", type: :boolean, default: false, required: false, desc: "Verbose output. Default: false"
|
70
73
|
|
71
74
|
def create_version_tag
|
@@ -83,6 +86,7 @@ module PactBroker
|
|
83
86
|
method_option :broker_base_url, required: true, aliases: "-b", desc: "The base URL of the Pact Broker"
|
84
87
|
method_option :broker_username, aliases: "-u", desc: "Pact Broker basic auth username"
|
85
88
|
method_option :broker_password, aliases: "-p", desc: "Pact Broker basic auth password"
|
89
|
+
method_option :broker_token, aliases: "-k", desc: "Pact Broker bearer token"
|
86
90
|
method_option :output, aliases: "-o", desc: "json or table or id", default: 'table'
|
87
91
|
method_option :verbose, aliases: "-v", type: :boolean, default: false, required: false, desc: "Verbose output. Default: false"
|
88
92
|
|
@@ -112,6 +116,7 @@ module PactBroker
|
|
112
116
|
method_option :broker_base_url, required: true, aliases: "-b", desc: "The base URL of the Pact Broker"
|
113
117
|
method_option :broker_username, aliases: "-u", desc: "Pact Broker basic auth username"
|
114
118
|
method_option :broker_password, aliases: "-p", desc: "Pact Broker basic auth password"
|
119
|
+
method_option :broker_token, aliases: "-k", desc: "Pact Broker bearer token"
|
115
120
|
method_option :contract_content_changed, type: :boolean, desc: "Trigger this webhook when the pact content changes"
|
116
121
|
method_option :provider_verification_published, type: :boolean, desc: "Trigger this webhook when a provider verification result is published"
|
117
122
|
method_option :verbose, aliases: "-v", type: :boolean, default: false, required: false, desc: "Verbose output. Default: false"
|
@@ -215,19 +220,15 @@ module PactBroker
|
|
215
220
|
end
|
216
221
|
|
217
222
|
def pact_broker_client_options
|
223
|
+
client_options = { verbose: options.verbose, token: options.broker_token }
|
218
224
|
if options.broker_username
|
219
|
-
{
|
220
|
-
basic_auth: {
|
225
|
+
client_options[:basic_auth] = {
|
221
226
|
username: options.broker_username,
|
222
227
|
password: options.broker_password
|
223
|
-
}
|
224
|
-
verbose: options.verbose
|
225
|
-
}
|
226
|
-
else
|
227
|
-
{
|
228
|
-
verbose: options.verbose
|
229
|
-
}
|
228
|
+
}
|
230
229
|
end
|
230
|
+
|
231
|
+
client_options
|
231
232
|
end
|
232
233
|
end
|
233
234
|
end
|
@@ -24,6 +24,7 @@ module PactBroker
|
|
24
24
|
|
25
25
|
new_argv = add_option_from_environment_variable(argv, 'broker-base-url', 'b', 'PACT_BROKER_BASE_URL')
|
26
26
|
new_argv = add_option_from_environment_variable(new_argv, 'broker-username', 'u', 'PACT_BROKER_USERNAME')
|
27
|
+
new_argv = add_option_from_environment_variable(new_argv, 'broker-token', 'k', 'PACT_BROKER_TOKEN')
|
27
28
|
add_option_from_environment_variable(new_argv, 'broker-password', 'p', 'PACT_BROKER_PASSWORD')
|
28
29
|
end
|
29
30
|
|
@@ -16,7 +16,9 @@ module PactBroker
|
|
16
16
|
]
|
17
17
|
|
18
18
|
def self.call(matrix)
|
19
|
-
|
19
|
+
matrix_rows = matrix[:matrix]
|
20
|
+
return "" if matrix_rows.size == 0
|
21
|
+
data = matrix_rows.collect do | line |
|
20
22
|
Line.new(
|
21
23
|
lookup(line, :consumer, :name),
|
22
24
|
lookup(line, :consumer, :version, :number),
|
@@ -18,7 +18,7 @@ module PactBroker
|
|
18
18
|
module Client
|
19
19
|
class PublicationTask < ::Rake::TaskLib
|
20
20
|
|
21
|
-
attr_accessor :pattern, :pact_broker_base_url, :consumer_version, :tag, :write_method, :tag_with_git_branch, :pact_broker_basic_auth
|
21
|
+
attr_accessor :pattern, :pact_broker_base_url, :consumer_version, :tag, :write_method, :tag_with_git_branch, :pact_broker_basic_auth, :pact_broker_token
|
22
22
|
alias_method :tags=, :tag=
|
23
23
|
alias_method :tags, :tag
|
24
24
|
|
@@ -37,8 +37,10 @@ module PactBroker
|
|
37
37
|
task task_name do
|
38
38
|
block.call(self)
|
39
39
|
require 'pact_broker/client/publish_pacts'
|
40
|
-
|
41
|
-
|
40
|
+
pact_broker_client_options = {}
|
41
|
+
.merge( pact_broker_basic_auth ? { basic_auth: pact_broker_basic_auth } : {} )
|
42
|
+
.merge( write_method ? { write: write_method } : {} )
|
43
|
+
.merge( pact_broker_token ? { token: pact_broker_token } : {} )
|
42
44
|
success = PactBroker::Client::PublishPacts.new(pact_broker_base_url, FileList[pattern], consumer_version, all_tags, pact_broker_client_options).call
|
43
45
|
raise "One or more pacts failed to be published" unless success
|
44
46
|
end
|
@@ -8,14 +8,17 @@ module PactBroker
|
|
8
8
|
let(:base_url) { 'http://pact_broker_base_url'}
|
9
9
|
let(:username) { 'pact_repo_username'}
|
10
10
|
let(:password) { 'pact_repo_password'}
|
11
|
+
let(:token) { '123456789' }
|
11
12
|
let(:client_options) do
|
12
|
-
{
|
13
|
+
{
|
13
14
|
basic_auth: {
|
14
15
|
username: username,
|
15
16
|
password: password
|
16
|
-
}
|
17
|
+
},
|
18
|
+
token: token
|
17
19
|
}
|
18
20
|
end
|
21
|
+
|
19
22
|
context 'with basic url' do
|
20
23
|
it 'sets the base url' do
|
21
24
|
base_client = BaseClient.new(base_url: base_url)
|
@@ -26,13 +29,22 @@ module PactBroker
|
|
26
29
|
|
27
30
|
context 'with client options' do
|
28
31
|
subject { BaseClient.new(base_url: base_url, client_options: client_options) }
|
29
|
-
it 'sets the client options
|
32
|
+
it 'sets the client options' do
|
30
33
|
expect(subject.client_options).to eq(client_options)
|
31
34
|
end
|
32
35
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
+
context 'when client options contains basic auth' do
|
37
|
+
it 'sets the httpparty basic auth' do
|
38
|
+
expect(BaseClient).to receive(:basic_auth).with(username, password)
|
39
|
+
subject
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'when client options contains broker token' do
|
44
|
+
it 'sets the httparty broker token' do
|
45
|
+
expect(BaseClient).to receive(:headers).with('Authorization' => "Bearer #{token}")
|
46
|
+
subject
|
47
|
+
end
|
36
48
|
end
|
37
49
|
end
|
38
50
|
|
@@ -46,6 +58,11 @@ module PactBroker
|
|
46
58
|
expect(BaseClient).to_not receive(:basic_auth).with(username, password)
|
47
59
|
subject
|
48
60
|
end
|
61
|
+
|
62
|
+
it 'does not set the httparty broker token' do
|
63
|
+
expect(BaseClient).to_not receive(:headers).with('Authorization' => "Bearer #{token}")
|
64
|
+
subject
|
65
|
+
end
|
49
66
|
end
|
50
67
|
|
51
68
|
context 'when the SSL_CERT_FILE environment variable is set' do
|
@@ -20,6 +20,7 @@ module PactBroker
|
|
20
20
|
{
|
21
21
|
broker_base_url: 'http://pact-broker',
|
22
22
|
output: 'table',
|
23
|
+
broker_token: 'token',
|
23
24
|
verbose: 'verbose',
|
24
25
|
retry_while_unknown: 1,
|
25
26
|
retry_interval: 2
|
@@ -34,7 +35,7 @@ module PactBroker
|
|
34
35
|
end
|
35
36
|
|
36
37
|
it "invokes the CanIDeploy service" do
|
37
|
-
expect(CanIDeploy).to receive(:call).with('http://pact-broker', version_selectors, {to_tag: nil}, {output: 'table', retry_while_unknown: 1, retry_interval: 2}, {verbose: 'verbose'})
|
38
|
+
expect(CanIDeploy).to receive(:call).with('http://pact-broker', version_selectors, {to_tag: nil}, {output: 'table', retry_while_unknown: 1, retry_interval: 2}, {token: 'token', verbose: 'verbose'})
|
38
39
|
invoke_can_i_deploy
|
39
40
|
end
|
40
41
|
|
@@ -64,7 +65,7 @@ module PactBroker
|
|
64
65
|
end
|
65
66
|
|
66
67
|
it "invokes the CanIDeploy service with the basic auth credentials" do
|
67
|
-
expect(CanIDeploy).to receive(:call).with(anything, anything, anything, anything, {basic_auth: {username: "foo", password: "bar"}, verbose: 'verbose'})
|
68
|
+
expect(CanIDeploy).to receive(:call).with(anything, anything, anything, anything, {basic_auth: {username: "foo", password: "bar"}, token: 'token', verbose: 'verbose'})
|
68
69
|
invoke_can_i_deploy
|
69
70
|
end
|
70
71
|
end
|
@@ -30,6 +30,7 @@ module PactBroker
|
|
30
30
|
broker_base_url: "http://broker",
|
31
31
|
broker_username: "username",
|
32
32
|
broker_password: "password",
|
33
|
+
broker_token: "token",
|
33
34
|
contract_content_changed: true,
|
34
35
|
verbose: true
|
35
36
|
}
|
@@ -62,7 +63,7 @@ module PactBroker
|
|
62
63
|
it "calls PactBroker::Client::Webhooks::Create with pact broker details" do
|
63
64
|
expect(PactBroker::Client::Webhooks::Create).to receive(:call) do | _, broker_base_url, pact_broker_client_options |
|
64
65
|
expect(broker_base_url).to eq "http://broker"
|
65
|
-
expect(pact_broker_client_options).to eq(basic_auth: { username: "username", password: "password"}, verbose: true)
|
66
|
+
expect(pact_broker_client_options).to eq(basic_auth: { username: "username", password: "password"}, token: "token", verbose: true)
|
66
67
|
command_result
|
67
68
|
end
|
68
69
|
subject
|
@@ -88,7 +89,7 @@ module PactBroker
|
|
88
89
|
|
89
90
|
it "calls Webhooks::Create without basic auth" do
|
90
91
|
expect(PactBroker::Client::Webhooks::Create).to receive(:call) do | _, _, pact_broker_client_options |
|
91
|
-
expect(pact_broker_client_options).to eq(verbose: true)
|
92
|
+
expect(pact_broker_client_options).to eq(token: "token", verbose: true)
|
92
93
|
command_result
|
93
94
|
end
|
94
95
|
subject
|
@@ -22,6 +22,7 @@ module PactBroker::Client::CLI
|
|
22
22
|
method_option :broker_base_url, required: true, aliases: "-b"
|
23
23
|
method_option :broker_username, aliases: "-u"
|
24
24
|
method_option :broker_password, aliases: "-p"
|
25
|
+
method_option :broker_token, aliases: "-k"
|
25
26
|
def test_using_env_vars
|
26
27
|
Delegate.call(options)
|
27
28
|
end
|
@@ -42,6 +43,7 @@ module PactBroker::Client::CLI
|
|
42
43
|
ENV['PACT_BROKER_BASE_URL'] = 'http://foo'
|
43
44
|
ENV['PACT_BROKER_USERNAME'] = 'username'
|
44
45
|
ENV['PACT_BROKER_PASSWORD'] = 'password'
|
46
|
+
ENV['PACT_BROKER_TOKEN'] = 'token'
|
45
47
|
end
|
46
48
|
|
47
49
|
it "populates the options from the environment variables" do
|
@@ -49,6 +51,7 @@ module PactBroker::Client::CLI
|
|
49
51
|
expect(options.broker_base_url).to eq 'http://foo'
|
50
52
|
expect(options.broker_username).to eq 'username'
|
51
53
|
expect(options.broker_password).to eq 'password'
|
54
|
+
expect(options.broker_token).to eq 'token'
|
52
55
|
end
|
53
56
|
TestThor.start(%w{test_using_env_vars})
|
54
57
|
end
|
@@ -58,6 +61,7 @@ module PactBroker::Client::CLI
|
|
58
61
|
expect(options.broker_base_url).to eq 'http://bar'
|
59
62
|
expect(options.broker_username).to eq 'username'
|
60
63
|
expect(options.broker_password).to eq 'password'
|
64
|
+
expect(options.broker_token).to eq 'token'
|
61
65
|
end
|
62
66
|
TestThor.start(%w{test_using_env_vars --broker-base-url http://bar})
|
63
67
|
end
|
@@ -12,9 +12,7 @@ module PactBroker
|
|
12
12
|
before do
|
13
13
|
FakeFS.activate!
|
14
14
|
allow(pacts_client).to receive(:publish).and_return(latest_pact_url)
|
15
|
-
allow(PactBroker::Client::PactBrokerClient).to receive(:new)
|
16
|
-
.with(base_url: pact_broker_base_url, client_options: pact_broker_client_options)
|
17
|
-
.and_return(pact_broker_client)
|
15
|
+
allow(PactBroker::Client::PactBrokerClient).to receive(:new).and_return(pact_broker_client)
|
18
16
|
allow(pact_broker_client).to receive_message_chain(:pacticipants, :versions).and_return(pact_versions_client)
|
19
17
|
allow(pact_broker_client).to receive_message_chain(:pacticipants, :versions, :pacts).and_return(pacts_client)
|
20
18
|
allow(pacts_client).to receive(:version_published?).and_return(false)
|
@@ -53,6 +51,10 @@ module PactBroker
|
|
53
51
|
subject { PublishPacts.new(pact_broker_base_url, pact_file_paths, consumer_version, tags, pact_broker_client_options) }
|
54
52
|
|
55
53
|
describe "call" do
|
54
|
+
it "creates a PactBroker Client" do
|
55
|
+
expect(PactBroker::Client::PactBrokerClient).to receive(:new).with(base_url: pact_broker_base_url, client_options: pact_broker_client_options)
|
56
|
+
subject.call
|
57
|
+
end
|
56
58
|
|
57
59
|
it "uses the pact_broker client to publish the given pact" do
|
58
60
|
expect(pacts_client).to receive(:publish).with(pact_hash: pact_hash, consumer_version: consumer_version)
|
@@ -81,7 +81,8 @@ module PactBroker::Client
|
|
81
81
|
before :all do
|
82
82
|
@pact_broker_base_url = "http://some-host"
|
83
83
|
@pattern = "pact/*.json"
|
84
|
-
@pact_broker_basic_auth = { username: 'user', password: 'pass'}
|
84
|
+
@pact_broker_basic_auth = { username: 'user', password: 'pass' }
|
85
|
+
@pact_broker_token = 'token'
|
85
86
|
@tag = "dev"
|
86
87
|
PactBroker::Client::PublicationTask.new(:custom) do | task |
|
87
88
|
task.consumer_version = '1.2.3'
|
@@ -89,13 +90,20 @@ module PactBroker::Client
|
|
89
90
|
task.pact_broker_base_url = @pact_broker_base_url
|
90
91
|
task.pattern = @pattern
|
91
92
|
task.pact_broker_basic_auth = @pact_broker_basic_auth
|
93
|
+
task.pact_broker_token = @pact_broker_token
|
92
94
|
end
|
93
95
|
end
|
94
96
|
|
95
97
|
let(:pattern) { @pattern }
|
96
98
|
|
97
99
|
it "invokes PublishPacts with the customised values" do
|
98
|
-
expect(PactBroker::Client::PublishPacts).to receive(:new).with(
|
100
|
+
expect(PactBroker::Client::PublishPacts).to receive(:new).with(
|
101
|
+
@pact_broker_base_url,
|
102
|
+
pact_file_list,
|
103
|
+
'1.2.3',
|
104
|
+
[@tag],
|
105
|
+
{ basic_auth: @pact_broker_basic_auth, token: @pact_broker_token }
|
106
|
+
)
|
99
107
|
expect(publish_pacts).to receive(:call).and_return(true)
|
100
108
|
Rake::Task['pact:publish:custom'].execute
|
101
109
|
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.18.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:
|
11
|
+
date: 2019-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|