pact_broker-client 1.37.0 → 1.38.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +28 -0
- data/bin/pact-broker +6 -0
- data/lib/pact_broker/client/base_client.rb +1 -1
- data/lib/pact_broker/client/cli/broker.rb +43 -7
- data/lib/pact_broker/client/cli/create_or_update_webhook_long_desc.txt +3 -1
- data/lib/pact_broker/client/cli/create_webhook_long_desc.txt +2 -0
- data/lib/pact_broker/client/cli/custom_thor.rb +2 -5
- data/lib/pact_broker/client/hal/entity.rb +17 -0
- data/lib/pact_broker/client/hal/http_client.rb +34 -2
- data/lib/pact_broker/client/version.rb +1 -1
- data/lib/pact_broker/client/versions/record_undeployment.rb +125 -0
- data/pact-broker-client.gemspec +1 -1
- data/script/record-deployment.sh +4 -0
- data/spec/lib/pact_broker/client/cli/broker_can_i_deploy_spec.rb +38 -4
- data/spec/lib/pact_broker/client/cli/broker_publish_spec.rb +1 -1
- data/spec/lib/pact_broker/client/cli/custom_thor_spec.rb +1 -7
- data/spec/lib/pact_broker/client/hal/http_client_spec.rb +64 -7
- data/spec/spec_helper.rb +2 -0
- metadata +9 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7e8fccfd3284da577d92cac60037f56d293b613ac0dd1d3b58a439027ef6401
|
4
|
+
data.tar.gz: 806f879281896358482de7cd2a0dd880688fded9a7f29f9da2f41f783cd782b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81f3b06673555261c984203492523162b54ead2221701e1c5d474de22ec7e7a03cca95c0289f86532d739f0d4dbeac104e8abd55e315d262c84d6e847159e269
|
7
|
+
data.tar.gz: 52d2a1c8ff9ed55a73b45991b459d11a9240f7eec1c9863d0625bb740a853ed7d811106537cf91ce5ffbe9581cb9cb26b94fdd4d61a797ba59e2aef37002f8c1
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,31 @@
|
|
1
|
+
<a name="v1.38.3"></a>
|
2
|
+
### v1.38.3 (2021-04-08)
|
3
|
+
|
4
|
+
#### Bug Fixes
|
5
|
+
|
6
|
+
* URL encode parameters for HAL templated URLs ([764a0fa](/../../commit/764a0fa))
|
7
|
+
|
8
|
+
<a name="v1.38.2"></a>
|
9
|
+
### v1.38.2 (2021-04-01)
|
10
|
+
|
11
|
+
#### Features
|
12
|
+
|
13
|
+
* allow SSL verification to be disabled ([eb2125b](/../../commit/eb2125b))
|
14
|
+
* automatically retry at the http client level for 50x responses ([a7343f8](/../../commit/a7343f8))
|
15
|
+
|
16
|
+
<a name="v1.38.1"></a>
|
17
|
+
### v1.38.1 (2021-03-22)
|
18
|
+
|
19
|
+
<a name="v1.38.0"></a>
|
20
|
+
### v1.38.0 (2021-03-22)
|
21
|
+
|
22
|
+
<a name="v1.37.1"></a>
|
23
|
+
### v1.37.1 (2021-03-11)
|
24
|
+
|
25
|
+
#### Bug Fixes
|
26
|
+
|
27
|
+
* set username from PACT_BROKER_USERNAME environment variable correctly when -u specified for create-or-update-webhook and create-webhook ([2411396](/../../commit/2411396))
|
28
|
+
|
1
29
|
<a name="v1.37.0"></a>
|
2
30
|
### v1.37.0 (2021-03-01)
|
3
31
|
|
data/bin/pact-broker
CHANGED
@@ -1,4 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'pact_broker/client/cli/broker'
|
3
3
|
|
4
|
+
if ENV['PACT_BROKER_DISABLE_SSL_VERIFICATION'] == 'true' || ENV['PACT_DISABLE_SSL_VERIFICATION'] == 'true'
|
5
|
+
require 'openssl'
|
6
|
+
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
|
7
|
+
$stderr.puts "WARN: SSL verification has been disabled by a dodgy hack (reassigning the VERIFY_PEER constant to VERIFY_NONE). You acknowledge that you do this at your own risk!"
|
8
|
+
end
|
9
|
+
|
4
10
|
PactBroker::Client::CLI::Broker.start
|
@@ -39,7 +39,8 @@ module PactBroker
|
|
39
39
|
can_i_deploy_options = { output: options.output, retry_while_unknown: options.retry_while_unknown, retry_interval: options.retry_interval }
|
40
40
|
result = CanIDeploy.call(options.broker_base_url, selectors, { to_tag: options.to, to_environment: options.to_environment, limit: options.limit }, can_i_deploy_options, pact_broker_client_options)
|
41
41
|
$stdout.puts result.message
|
42
|
-
|
42
|
+
$stdout.flush
|
43
|
+
exit(can_i_deploy_exit_status) unless result.success
|
43
44
|
end
|
44
45
|
|
45
46
|
desc 'publish PACT_DIRS_OR_FILES ...', "Publish pacts to a Pact Broker."
|
@@ -197,6 +198,31 @@ module PactBroker
|
|
197
198
|
exit(1) unless result.success
|
198
199
|
end
|
199
200
|
|
201
|
+
ignored_and_hidden_potential_options_from_environment_variables
|
202
|
+
desc "record-undeployment", "Record undeployment of (or the end of support for) a pacticipant version from an environment"
|
203
|
+
method_option :pacticipant, required: true, aliases: "-a", desc: "The name of the pacticipant that was deployed."
|
204
|
+
method_option :version, required: true, aliases: "-e", desc: "The pacticipant version number that was deployed."
|
205
|
+
method_option :environment, required: true, desc: "The name of the environment that the pacticipant version was deployed to."
|
206
|
+
method_option :output, aliases: "-o", desc: "json or text", default: 'text'
|
207
|
+
shared_authentication_options
|
208
|
+
|
209
|
+
def record_undeployment
|
210
|
+
require 'pact_broker/client/versions/record_undeployment'
|
211
|
+
params = {
|
212
|
+
pacticipant_name: options.pacticipant,
|
213
|
+
version_number: options.version,
|
214
|
+
environment_name: options.environment,
|
215
|
+
output: options.output
|
216
|
+
}
|
217
|
+
result = PactBroker::Client::Versions::RecordUndeployment.call(
|
218
|
+
params,
|
219
|
+
options.broker_base_url,
|
220
|
+
pact_broker_client_options
|
221
|
+
)
|
222
|
+
$stdout.puts result.message
|
223
|
+
exit(1) unless result.success
|
224
|
+
end
|
225
|
+
|
200
226
|
end
|
201
227
|
|
202
228
|
ignored_and_hidden_potential_options_from_environment_variables
|
@@ -213,6 +239,16 @@ module PactBroker
|
|
213
239
|
true
|
214
240
|
end
|
215
241
|
|
242
|
+
def can_i_deploy_exit_status
|
243
|
+
exit_code_string = ENV.fetch('PACT_BROKER_CAN_I_DEPLOY_EXIT_CODE_BETA', '')
|
244
|
+
if exit_code_string =~ /^\d+$/
|
245
|
+
$stderr.puts "Exiting can-i-deploy with configured exit code #{exit_code_string}"
|
246
|
+
exit_code_string.to_i
|
247
|
+
else
|
248
|
+
1
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
216
252
|
def validate_credentials
|
217
253
|
if options.broker_username && options.broker_token
|
218
254
|
raise AuthError, "You cannot provide both a username/password and a bearer token. If your Pact Broker uses a bearer token, please remove the username and password configuration."
|
@@ -287,15 +323,15 @@ module PactBroker
|
|
287
323
|
|
288
324
|
def pact_broker_client_options
|
289
325
|
client_options = { verbose: options.verbose }
|
290
|
-
client_options[:token] =
|
291
|
-
if options.broker_username
|
326
|
+
client_options[:token] = options.broker_token || ENV['PACT_BROKER_TOKEN']
|
327
|
+
if options.broker_username || ENV['PACT_BROKER_USERNAME']
|
292
328
|
client_options[:basic_auth] = {
|
293
|
-
username: options.broker_username,
|
294
|
-
password: options.broker_password
|
295
|
-
}
|
329
|
+
username: options.broker_username || ENV['PACT_BROKER_USERNAME'],
|
330
|
+
password: options.broker_password || ENV['PACT_BROKER_PASSWORD']
|
331
|
+
}.compact
|
296
332
|
end
|
297
333
|
|
298
|
-
client_options
|
334
|
+
client_options.compact
|
299
335
|
end
|
300
336
|
|
301
337
|
def parse_webhook_events
|
@@ -1 +1,3 @@
|
|
1
|
-
Create a curl command that executes the request that you want your webhook to execute, then replace "curl" with "pact-broker create-or-update-webhook" and add the consumer, provider, event types and broker details. Note that the URL must be the first parameter when executing create-or-update-webhook and a uuid must also be provided. You can generate a valid UUID by using the `generate-uuid` command.
|
1
|
+
Create a curl command that executes the request that you want your webhook to execute, then replace "curl" with "pact-broker create-or-update-webhook" and add the consumer, provider, event types and broker details. Note that the URL must be the first parameter when executing create-or-update-webhook and a uuid must also be provided. You can generate a valid UUID by using the `generate-uuid` command.
|
2
|
+
|
3
|
+
Note that the -u option from the curl command clashes with the -u option from the pact-broker CLI. When used in this command, the -u will be used as a curl option. Please use the --broker-username or environment variable for the Pact Broker username.
|
@@ -1 +1,3 @@
|
|
1
1
|
Create a curl command that executes the request that you want your webhook to execute, then replace "curl" with "pact-broker create-webhook" and add the consumer, provider, event types and broker details. Note that the URL must be the first parameter when executing create-webhook.
|
2
|
+
|
3
|
+
Note that the -u option from the curl command clashes with the -u option from the pact-broker CLI. When used in this command, the -u will be used as a curl option. Please use the --broker-username or environment variable for the Pact Broker username.
|
@@ -22,10 +22,7 @@ module PactBroker
|
|
22
22
|
def self.add_broker_config_from_environment_variables argv
|
23
23
|
return argv if argv[0] == 'help' || argv.empty?
|
24
24
|
|
25
|
-
|
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')
|
28
|
-
add_option_from_environment_variable(new_argv, 'broker-password', 'p', 'PACT_BROKER_PASSWORD')
|
25
|
+
add_option_from_environment_variable(argv, 'broker-base-url', 'b', 'PACT_BROKER_BASE_URL')
|
29
26
|
end
|
30
27
|
|
31
28
|
def self.add_option_from_environment_variable argv, long_name, short_name, environment_variable_name
|
@@ -117,4 +114,4 @@ module PactBroker
|
|
117
114
|
end
|
118
115
|
end
|
119
116
|
end
|
120
|
-
end
|
117
|
+
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'erb'
|
2
2
|
require 'delegate'
|
3
|
+
require 'pact_broker/client/error'
|
3
4
|
require 'pact_broker/client/hal/link'
|
4
5
|
require 'pact_broker/client/hal/links'
|
5
6
|
|
@@ -73,6 +74,22 @@ module PactBroker
|
|
73
74
|
_links(key) or raise RelationNotFoundError.new("Could not find relation '#{key}' in resource at #{@href}")
|
74
75
|
end
|
75
76
|
|
77
|
+
def embedded_entity
|
78
|
+
embedded_ent = yield @data["_embedded"]
|
79
|
+
Entity.new(embedded_ent["_links"]["self"]["href"], embedded_ent, @client, response)
|
80
|
+
end
|
81
|
+
|
82
|
+
def embedded_entities(key = nil)
|
83
|
+
embedded_ents = if key
|
84
|
+
@data["_embedded"][key]
|
85
|
+
else
|
86
|
+
yield @data["_embedded"]
|
87
|
+
end
|
88
|
+
embedded_ents.collect do | embedded_ent |
|
89
|
+
Entity.new(embedded_ent["_links"]["self"]["href"], embedded_ent, @client, response)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
76
93
|
def success?
|
77
94
|
true
|
78
95
|
end
|
@@ -7,6 +7,7 @@ module PactBroker
|
|
7
7
|
module Client
|
8
8
|
module Hal
|
9
9
|
class HttpClient
|
10
|
+
RETRYABLE_ERRORS = [Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::ETIMEDOUT, Errno::EHOSTUNREACH, Net::ReadTimeout]
|
10
11
|
attr_accessor :username, :password, :verbose, :token
|
11
12
|
|
12
13
|
def initialize options
|
@@ -17,7 +18,7 @@ module PactBroker
|
|
17
18
|
end
|
18
19
|
|
19
20
|
def get href, params = {}, headers = {}
|
20
|
-
query = params.collect{ |(key, value)| "#{CGI::escape(key)}=#{CGI::escape(value)}" }.join("&")
|
21
|
+
query = params.collect{ |(key, value)| "#{CGI::escape(key.to_s)}=#{CGI::escape(value)}" }.join("&")
|
21
22
|
uri = URI(href)
|
22
23
|
uri.query = query
|
23
24
|
perform_request(create_request(uri, 'Get', nil, headers), uri)
|
@@ -53,7 +54,7 @@ module PactBroker
|
|
53
54
|
end
|
54
55
|
|
55
56
|
def perform_request request, uri
|
56
|
-
response =
|
57
|
+
response = until_truthy_or_max_times(times: 5, sleep: 5, condition: ->(resp) { resp.code.to_i < 500 }) do
|
57
58
|
http = Net::HTTP.new(uri.host, uri.port, :ENV)
|
58
59
|
http.set_debug_output(output_stream) if verbose
|
59
60
|
http.use_ssl = (uri.scheme == 'https')
|
@@ -69,6 +70,37 @@ module PactBroker
|
|
69
70
|
Response.new(response)
|
70
71
|
end
|
71
72
|
|
73
|
+
def until_truthy_or_max_times options = {}
|
74
|
+
max_tries = options.fetch(:times, 3)
|
75
|
+
tries = 0
|
76
|
+
sleep_interval = options.fetch(:sleep, 5)
|
77
|
+
sleep(sleep_interval) if options[:sleep_first]
|
78
|
+
while true
|
79
|
+
begin
|
80
|
+
result = yield
|
81
|
+
return result if max_tries < 2
|
82
|
+
if options[:condition]
|
83
|
+
condition_result = options[:condition].call(result)
|
84
|
+
return result if condition_result
|
85
|
+
else
|
86
|
+
return result if result
|
87
|
+
end
|
88
|
+
tries += 1
|
89
|
+
return result if max_tries == tries
|
90
|
+
sleep sleep_interval
|
91
|
+
rescue *RETRYABLE_ERRORS => e
|
92
|
+
tries += 1
|
93
|
+
$stderr.puts "ERROR: Error making request - #{e.class} #{e.message} #{e.backtrace.find{|l| l.include?('pact_broker-client')}}, attempt #{tries} of #{max_tries}"
|
94
|
+
raise e if max_tries == tries
|
95
|
+
sleep sleep_interval
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def sleep seconds
|
101
|
+
Kernel.sleep seconds
|
102
|
+
end
|
103
|
+
|
72
104
|
def output_stream
|
73
105
|
AuthorizationHeaderRedactor.new($stdout)
|
74
106
|
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
require 'pact_broker/client/hal_client_methods'
|
2
|
+
require 'pact_broker/client/error'
|
3
|
+
require 'pact_broker/client/command_result'
|
4
|
+
|
5
|
+
module PactBroker
|
6
|
+
module Client
|
7
|
+
class Versions
|
8
|
+
class RecordUndeployment
|
9
|
+
include PactBroker::Client::HalClientMethods
|
10
|
+
|
11
|
+
NOT_SUPPORTED_MESSAGE = "This version of the Pact Broker does not support recording undeployments. Please upgrade to version 2.80.0 or later."
|
12
|
+
|
13
|
+
def self.call(params, pact_broker_base_url, pact_broker_client_options)
|
14
|
+
new(params, pact_broker_base_url, pact_broker_client_options).call
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(params, pact_broker_base_url, pact_broker_client_options)
|
18
|
+
@pact_broker_base_url = pact_broker_base_url
|
19
|
+
@pacticipant_name = params.fetch(:pacticipant_name)
|
20
|
+
@version_number = params.fetch(:version_number)
|
21
|
+
@environment_name = params.fetch(:environment_name)
|
22
|
+
@output = params.fetch(:output)
|
23
|
+
@pact_broker_client_options = pact_broker_client_options
|
24
|
+
end
|
25
|
+
|
26
|
+
def call
|
27
|
+
check_environment_exists
|
28
|
+
# record_undeployment
|
29
|
+
|
30
|
+
PactBroker::Client::CommandResult.new(true, result_message)
|
31
|
+
rescue PactBroker::Client::Error => e
|
32
|
+
PactBroker::Client::CommandResult.new(false, e.message)
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
attr_reader :pact_broker_base_url, :pact_broker_client_options
|
38
|
+
attr_reader :pacticipant_name, :version_number, :environment_name, :replaced_previous_deployed_version, :output
|
39
|
+
attr_reader :deployed_version_resource
|
40
|
+
|
41
|
+
def check_environment_exists
|
42
|
+
deployed_versions = currently_deployed_versions_for_pacticipant
|
43
|
+
.get(version: version_number)
|
44
|
+
.embedded_entities("deployedVersions")
|
45
|
+
deployed_versions
|
46
|
+
end
|
47
|
+
|
48
|
+
def currently_deployed_versions_for_pacticipant
|
49
|
+
@currently_deployed_versions_for_pacticipant ||= index_resource
|
50
|
+
._link!("pb:environments")
|
51
|
+
.get!(name: environment_name)
|
52
|
+
.embedded_entities("environments")
|
53
|
+
.tap { |it| raise "Environment not found '#{environment_name}'" if it.empty? }
|
54
|
+
.first
|
55
|
+
._link!("pb:currently-deployed-versions-for-pacticipant")
|
56
|
+
.expand(pacticipant: pacticipant_name)
|
57
|
+
end
|
58
|
+
|
59
|
+
def currently_deployed_versions_for_pacticipant_version
|
60
|
+
@currently_deployed_versions ||= currently_deployed_versions_for_pacticipant
|
61
|
+
.get(version: version_number)
|
62
|
+
.embedded_entities("deployedVersions")
|
63
|
+
end
|
64
|
+
|
65
|
+
# def record_deployment
|
66
|
+
# @deployed_version_resource =
|
67
|
+
# get_record_deployment_relation
|
68
|
+
# .post(record_deployment_request_body)
|
69
|
+
# .assert_success!
|
70
|
+
# end
|
71
|
+
|
72
|
+
# def get_record_deployment_relation
|
73
|
+
# record_deployment_links = get_pacticipant_version._links!("pb:record-deployment")
|
74
|
+
# link_for_environment = record_deployment_links.find(environment_name)
|
75
|
+
# if link_for_environment
|
76
|
+
# link_for_environment
|
77
|
+
# else
|
78
|
+
# check_environment_exists
|
79
|
+
# # Force the exception to be raised
|
80
|
+
# record_deployment_links.find!(environment_name, "Environment '#{environment_name}' is not an available option for recording a deployment of #{pacticipant_name}.")
|
81
|
+
# end
|
82
|
+
# end
|
83
|
+
|
84
|
+
# def get_pacticipant_version
|
85
|
+
# index_resource
|
86
|
+
# ._link!("pb:pacticipant-version")
|
87
|
+
# .expand(pacticipant: pacticipant_name, version: version_number)
|
88
|
+
# .get
|
89
|
+
# .assert_success!(404 => "#{pacticipant_name} version #{version_number} not found")
|
90
|
+
# end
|
91
|
+
|
92
|
+
# def record_deployment_request_body
|
93
|
+
# { replacedPreviousDeployedVersion: replaced_previous_deployed_version }
|
94
|
+
# end
|
95
|
+
|
96
|
+
def result_message
|
97
|
+
""
|
98
|
+
# if output == "text"
|
99
|
+
# message = "Recorded deployment of #{pacticipant_name} version #{version_number} to #{environment_name} in #{pact_broker_name}."
|
100
|
+
# suffix = replaced_previous_deployed_version ? " Marked previous deployed version as undeployed." : ""
|
101
|
+
# message + suffix
|
102
|
+
# elsif output == "json"
|
103
|
+
# deployed_version_resource.response.raw_body
|
104
|
+
# else
|
105
|
+
# ""
|
106
|
+
# end
|
107
|
+
end
|
108
|
+
|
109
|
+
def pact_broker_name
|
110
|
+
is_pactflow? ? "Pactflow" : "the Pact Broker"
|
111
|
+
end
|
112
|
+
|
113
|
+
def is_pactflow?
|
114
|
+
deployed_version_resource.response.headers.keys.any?{ | header_name | header_name.downcase.include?("pactflow") }
|
115
|
+
end
|
116
|
+
|
117
|
+
def check_if_command_supported
|
118
|
+
unless index_resource.can?("pb:environments")
|
119
|
+
raise PactBroker::Client::Error.new(NOT_SUPPORTED_MESSAGE)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
data/pact-broker-client.gemspec
CHANGED
@@ -32,5 +32,5 @@ Gem::Specification.new do |gem|
|
|
32
32
|
gem.add_development_dependency 'webmock', '~> 3.0'
|
33
33
|
gem.add_development_dependency 'conventional-changelog', '~>1.3'
|
34
34
|
gem.add_development_dependency 'pact', '~> 1.16'
|
35
|
-
gem.add_development_dependency 'pact-support', '1.
|
35
|
+
gem.add_development_dependency 'pact-support', '~> 1.16'
|
36
36
|
end
|
@@ -1,4 +1,6 @@
|
|
1
1
|
require 'pact_broker/client/cli/broker'
|
2
|
+
require 'pact_broker/client/cli/version_selector_options_parser'
|
3
|
+
require 'pact_broker/client/can_i_deploy'
|
2
4
|
|
3
5
|
module PactBroker
|
4
6
|
module Client
|
@@ -111,13 +113,45 @@ module PactBroker
|
|
111
113
|
end
|
112
114
|
|
113
115
|
it "exits with code 1" do
|
114
|
-
|
116
|
+
exited_explicitly = false
|
117
|
+
exited_explicitlyerror = nil
|
115
118
|
begin
|
116
119
|
invoke_can_i_deploy
|
117
|
-
rescue SystemExit
|
118
|
-
|
120
|
+
rescue SystemExit => e
|
121
|
+
exited_explicitly = true
|
122
|
+
error = e
|
123
|
+
end
|
124
|
+
expect(exited_explicitly).to be true
|
125
|
+
expect(error.status).to be 1
|
126
|
+
end
|
127
|
+
|
128
|
+
context "when an exit status is specified" do
|
129
|
+
before do
|
130
|
+
allow(ENV).to receive(:fetch).and_call_original
|
131
|
+
allow(ENV).to receive(:fetch).with('PACT_BROKER_CAN_I_DEPLOY_EXIT_CODE_BETA', '').and_return("0")
|
132
|
+
end
|
133
|
+
|
134
|
+
it "exits with the specified code" do
|
135
|
+
exited_explicitly = false
|
136
|
+
error = nil
|
137
|
+
begin
|
138
|
+
invoke_can_i_deploy
|
139
|
+
rescue SystemExit => e
|
140
|
+
exited_explicitly = true
|
141
|
+
error = e
|
142
|
+
end
|
143
|
+
expect(exited_explicitly).to be true
|
144
|
+
expect(error.status).to be 0
|
145
|
+
end
|
146
|
+
|
147
|
+
it "prints the configured exit code" do
|
148
|
+
expect($stderr).to receive(:puts).with("Exiting can-i-deploy with configured exit code 0")
|
149
|
+
expect($stdout).to receive(:puts).with(message)
|
150
|
+
begin
|
151
|
+
invoke_can_i_deploy
|
152
|
+
rescue SystemExit
|
153
|
+
end
|
119
154
|
end
|
120
|
-
expect(exited_with_error).to be true
|
121
155
|
end
|
122
156
|
end
|
123
157
|
end
|
@@ -52,12 +52,9 @@ module PactBroker::Client::CLI
|
|
52
52
|
ENV['PACT_BROKER_TOKEN'] = 'token'
|
53
53
|
end
|
54
54
|
|
55
|
-
it "populates the
|
55
|
+
it "populates the base URL from the environment variables" do
|
56
56
|
expect(Delegate).to receive(:call) do | options |
|
57
57
|
expect(options.broker_base_url).to eq 'http://foo'
|
58
|
-
expect(options.broker_username).to eq 'username'
|
59
|
-
expect(options.broker_password).to eq 'password'
|
60
|
-
expect(options.broker_token).to eq 'token'
|
61
58
|
end
|
62
59
|
TestThor.start(%w{test_using_env_vars})
|
63
60
|
end
|
@@ -65,9 +62,6 @@ module PactBroker::Client::CLI
|
|
65
62
|
it "does not override a value specifed on the command line" do
|
66
63
|
expect(Delegate).to receive(:call) do | options |
|
67
64
|
expect(options.broker_base_url).to eq 'http://bar'
|
68
|
-
expect(options.broker_username).to eq 'username'
|
69
|
-
expect(options.broker_password).to eq 'password'
|
70
|
-
expect(options.broker_token).to eq 'token'
|
71
65
|
end
|
72
66
|
TestThor.start(%w{test_using_env_vars --broker-base-url http://bar})
|
73
67
|
end
|
@@ -3,13 +3,13 @@ require 'pact_broker/client/hal/http_client'
|
|
3
3
|
module PactBroker::Client
|
4
4
|
module Hal
|
5
5
|
describe HttpClient do
|
6
|
-
before do
|
7
|
-
allow(Retry).to receive(:until_truthy_or_max_times) { |&block| block.call }
|
8
|
-
end
|
9
|
-
|
10
6
|
subject { HttpClient.new(username: 'foo', password: 'bar') }
|
11
7
|
|
12
8
|
describe "get" do
|
9
|
+
before do
|
10
|
+
allow(subject).to receive(:until_truthy_or_max_times) { |&block| block.call }
|
11
|
+
end
|
12
|
+
|
13
13
|
let!(:request) do
|
14
14
|
stub_request(:get, "http://example.org/").
|
15
15
|
with( headers: {
|
@@ -41,18 +41,22 @@ module PactBroker::Client
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
|
45
44
|
it "retries on failure" do
|
46
|
-
expect(
|
45
|
+
expect(subject).to receive(:until_truthy_or_max_times)
|
47
46
|
do_get
|
48
47
|
end
|
49
48
|
|
50
49
|
it "returns a response" do
|
51
50
|
expect(do_get.body).to eq({"some" => "json"})
|
52
51
|
end
|
52
|
+
|
53
53
|
end
|
54
54
|
|
55
55
|
describe "post" do
|
56
|
+
before do
|
57
|
+
allow(subject).to receive(:until_truthy_or_max_times) { |&block| block.call }
|
58
|
+
end
|
59
|
+
|
56
60
|
let!(:request) do
|
57
61
|
stub_request(:post, "http://example.org/").
|
58
62
|
with( headers: {
|
@@ -75,7 +79,7 @@ module PactBroker::Client
|
|
75
79
|
end
|
76
80
|
|
77
81
|
it "calls Retry.until_truthy_or_max_times" do
|
78
|
-
expect(
|
82
|
+
expect(subject).to receive(:until_truthy_or_max_times)
|
79
83
|
do_post
|
80
84
|
end
|
81
85
|
|
@@ -100,6 +104,59 @@ module PactBroker::Client
|
|
100
104
|
end
|
101
105
|
end
|
102
106
|
end
|
107
|
+
|
108
|
+
describe "integration test" do
|
109
|
+
before do
|
110
|
+
allow(subject).to receive(:sleep)
|
111
|
+
end
|
112
|
+
|
113
|
+
let(:do_get) { subject.get('http://example.org') }
|
114
|
+
|
115
|
+
context "with a 50x error is returned less than the max number of tries" do
|
116
|
+
let!(:request) do
|
117
|
+
stub_request(:get, "http://example.org").
|
118
|
+
to_return({ status: 500 }, { status: 502 }, { status: 503 }, { status: 200 })
|
119
|
+
end
|
120
|
+
|
121
|
+
it "retries" do
|
122
|
+
expect(do_get.status).to eq 200
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
context "with a 50x error is returned more than the max number of tries" do
|
127
|
+
let!(:request) do
|
128
|
+
stub_request(:get, "http://example.org").
|
129
|
+
to_return({ status: 500 }, { status: 501 }, { status: 502 }, { status: 503 }, { status: 504 })
|
130
|
+
end
|
131
|
+
|
132
|
+
it "retries and returns the last 50x response" do
|
133
|
+
expect(do_get.status).to eq 504
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
context "when exceptions are raised" do
|
138
|
+
before do
|
139
|
+
allow($stderr).to receive(:puts)
|
140
|
+
end
|
141
|
+
|
142
|
+
let!(:request) do
|
143
|
+
stub_request(:get, "http://example.org")
|
144
|
+
.to_raise(Errno::ECONNREFUSED)
|
145
|
+
end
|
146
|
+
|
147
|
+
it "logs the error" do
|
148
|
+
expect($stderr).to receive(:puts).with(/Errno::ECONNREFUSED/)
|
149
|
+
begin
|
150
|
+
do_get
|
151
|
+
rescue Errno::ECONNREFUSED
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
it "retries and raises the last exception" do
|
156
|
+
expect { do_get }.to raise_error(Errno::ECONNREFUSED)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
103
160
|
end
|
104
161
|
end
|
105
162
|
end
|
data/spec/spec_helper.rb
CHANGED
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.38.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Beth Skurrie
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -160,16 +160,16 @@ dependencies:
|
|
160
160
|
name: pact-support
|
161
161
|
requirement: !ruby/object:Gem::Requirement
|
162
162
|
requirements:
|
163
|
-
- -
|
163
|
+
- - "~>"
|
164
164
|
- !ruby/object:Gem::Version
|
165
|
-
version: 1.
|
165
|
+
version: '1.16'
|
166
166
|
type: :development
|
167
167
|
prerelease: false
|
168
168
|
version_requirements: !ruby/object:Gem::Requirement
|
169
169
|
requirements:
|
170
|
-
- -
|
170
|
+
- - "~>"
|
171
171
|
- !ruby/object:Gem::Version
|
172
|
-
version: 1.
|
172
|
+
version: '1.16'
|
173
173
|
description: Client for the Pact Broker. Publish, retrieve and query pacts and verification
|
174
174
|
results.
|
175
175
|
email:
|
@@ -249,6 +249,7 @@ files:
|
|
249
249
|
- lib/pact_broker/client/versions/formatter.rb
|
250
250
|
- lib/pact_broker/client/versions/json_formatter.rb
|
251
251
|
- lib/pact_broker/client/versions/record_deployment.rb
|
252
|
+
- lib/pact_broker/client/versions/record_undeployment.rb
|
252
253
|
- lib/pact_broker/client/versions/text_formatter.rb
|
253
254
|
- lib/pact_broker/client/webhooks/create.rb
|
254
255
|
- lib/pact_broker/client/webhooks/test.rb
|
@@ -257,6 +258,7 @@ files:
|
|
257
258
|
- script/create-pacticipant.sh
|
258
259
|
- script/generate-cli-usage.sh
|
259
260
|
- script/publish-pact.sh
|
261
|
+
- script/record-deployment.sh
|
260
262
|
- script/release.sh
|
261
263
|
- script/trigger-release.sh
|
262
264
|
- spec/integration/can_i_deploy_spec.rb
|
@@ -337,7 +339,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
337
339
|
- !ruby/object:Gem::Version
|
338
340
|
version: '0'
|
339
341
|
requirements: []
|
340
|
-
rubygems_version: 3.2.
|
342
|
+
rubygems_version: 3.2.15
|
341
343
|
signing_key:
|
342
344
|
specification_version: 4
|
343
345
|
summary: See description
|