pact_broker-client 1.15.1 → 1.16.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 81c3d29dfec163255db64e918be588a9611b7966
4
- data.tar.gz: 8f6b38b9f3090020f9aefdc1b5bc07d98c937986
3
+ metadata.gz: 86e1090888410192cf087270229f3b0542850d81
4
+ data.tar.gz: a4f841135438cdb6e5520dccf9fa812d2884f4a0
5
5
  SHA512:
6
- metadata.gz: 5cec2de1c03cd72dfcca66e1dde056aee37d03181ad5a8a1f94ac29d86b907ab5718f3a565201ef45fa82f82e4966f0651f517cbb0e09c475600edfb867d0ecf
7
- data.tar.gz: 7bd74b8249cf16c3255dd20c50c4683d216af7c088597dfc3c7115c3f30536b1811c87f8d714b20996ce33cf9c62d70a4124814eaea3decb18c2bfc9b5b28820
6
+ metadata.gz: eb5a27dd769ebb1e68ad2b0959a10f6af8ce00f1995f95bbfa5ee14ecf306536c0994d95db2aa7c84c52417b2a318231880b6f60d47357542525528d4e5600c1
7
+ data.tar.gz: 6e22a6ce47412481e76ea8834caa40c793b70c1d7fbfd2855da16384ae715339c5a52b8100090ba96dae54e375a932666316f951ada164bccf16c2903974d331
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ <a name="v1.16.0"></a>
2
+ ### v1.16.0 (2018-07-09)
3
+
4
+
5
+ #### Features
6
+
7
+ * add retries to can-i-deploy to allow the command to wait for missing results to arrive ([e44f88d](/../../commit/e44f88d))
8
+
9
+
1
10
  <a name="v1.15.1"></a>
2
11
  ### v1.15.1 (2018-06-28)
3
12
 
data/README.md CHANGED
@@ -67,12 +67,17 @@ Options:
67
67
  -a, --pacticipant=PACTICIPANT # The pacticipant name. Use once for each pacticipant being checked.
68
68
  -e, [--version=VERSION] # The pacticipant version. Must be entered after the --pacticipant that it relates to.
69
69
  -l, [--latest=[TAG]] # Use the latest pacticipant version. Optionally specify a TAG to use the latest version with the specified tag.
70
+ [--to=TAG] # This is too hard to explain in a short sentence. Look at the examples.
70
71
  -b, --broker-base-url=BROKER_BASE_URL # The base URL of the Pact Broker
71
72
  -u, [--broker-username=BROKER_USERNAME] # Pact Broker basic auth username
72
73
  -p, [--broker-password=BROKER_PASSWORD] # Pact Broker basic auth password
73
74
  -o, [--output=OUTPUT] # json or table
74
75
  # Default: table
75
76
  -v, [--verbose], [--no-verbose] # Verbose output. Default: false
77
+ [--retry-while-unknown=TIMES] # The number of times to retry while there is an unknown verification result (ie. the provider verification is likely still running)
78
+ # Default: 0
79
+ [--retry-interval=SECONDS] # The time between retries in seconds. Use in conjuction with --retry-while-unknown
80
+ # Default: 10
76
81
 
77
82
  Description:
78
83
  Returns exit code 0 or 1, indicating whether or not the specified pacticipant versions are compatible. Prints out the relevant pact/verification details.
@@ -196,7 +196,8 @@ Pact Broker will respond with:
196
196
  "body": {
197
197
  "summary": {
198
198
  "deployable": true,
199
- "reason": "some text"
199
+ "reason": "some text",
200
+ "unknown": 1
200
201
  },
201
202
  "matrix": [
202
203
  {
@@ -243,7 +244,8 @@ Pact Broker will respond with:
243
244
  "body": {
244
245
  "summary": {
245
246
  "deployable": true,
246
- "reason": "some text"
247
+ "reason": "some text",
248
+ "unknown": 1
247
249
  },
248
250
  "matrix": [
249
251
  {
@@ -290,7 +292,8 @@ Pact Broker will respond with:
290
292
  "body": {
291
293
  "summary": {
292
294
  "deployable": true,
293
- "reason": "some text"
295
+ "reason": "some text",
296
+ "unknown": 1
294
297
  },
295
298
  "matrix": [
296
299
  {
@@ -373,7 +376,8 @@ Pact Broker will respond with:
373
376
  "body": {
374
377
  "summary": {
375
378
  "deployable": true,
376
- "reason": "some text"
379
+ "reason": "some text",
380
+ "unknown": 1
377
381
  },
378
382
  "matrix": [
379
383
  {
@@ -443,7 +447,8 @@ Pact Broker will respond with:
443
447
  "body": {
444
448
  "summary": {
445
449
  "deployable": true,
446
- "reason": "some text"
450
+ "reason": "some text",
451
+ "unknown": 1
447
452
  },
448
453
  "matrix": [
449
454
  {
@@ -629,7 +634,8 @@ Pact Broker will respond with:
629
634
  "body": {
630
635
  "summary": {
631
636
  "deployable": true,
632
- "reason": "some text"
637
+ "reason": "some text",
638
+ "unknown": 1
633
639
  },
634
640
  "matrix": [
635
641
  {
@@ -1,3 +1,3 @@
1
1
  ### Pacts for Pact Broker Client
2
2
 
3
- * [Pact Broker](Pact Broker Client - Pact Broker.md)
3
+ * [Pact Broker](Pact%20Broker%20Client%20-%20Pact%20Broker.md)
@@ -30,11 +30,7 @@ module PactBroker
30
30
  end
31
31
 
32
32
  def call
33
- if matrix[:summary][:deployable]
34
- Result.new(true, success_message(matrix))
35
- else
36
- Result.new(false, failure_message(matrix))
37
- end
33
+ create_result(fetch_matrix_with_retries)
38
34
  rescue PactBroker::Client::Error => e
39
35
  Result.new(false, e.message)
40
36
  rescue StandardError => e
@@ -45,10 +41,18 @@ module PactBroker
45
41
 
46
42
  attr_reader :pact_broker_base_url, :version_selectors, :matrix_options, :options, :pact_broker_client_options
47
43
 
44
+ def create_result(matrix)
45
+ if matrix.deployable?
46
+ Result.new(true, success_message(matrix))
47
+ else
48
+ Result.new(false, failure_message(matrix))
49
+ end
50
+ end
51
+
48
52
  def success_message(matrix)
49
53
  message = format_matrix(matrix)
50
54
  if format != 'json'
51
- message = 'Computer says yes \o/ ' + "\n\n" + message + "\n\n#{Term::ANSIColor.green(reason(matrix))}"
55
+ message = 'Computer says yes \o/ ' + "\n\n" + message + "\n\n#{Term::ANSIColor.green(matrix.reason)}"
52
56
  end
53
57
  message
54
58
  end
@@ -56,7 +60,7 @@ module PactBroker
56
60
  def failure_message(matrix)
57
61
  message = format_matrix(matrix)
58
62
  if format != 'json'
59
- message = 'Computer says no ¯\_(ツ)_/¯ ' + "\n\n" + message + "\n\n#{Term::ANSIColor.red(reason(matrix))}"
63
+ message = 'Computer says no ¯\_(ツ)_/¯ ' + "\n\n" + message + "\n\n#{Term::ANSIColor.red(matrix.reason)}"
60
64
  end
61
65
  message
62
66
  end
@@ -69,17 +73,53 @@ module PactBroker
69
73
  options[:output]
70
74
  end
71
75
 
72
- def reason(matrix)
73
- matrix[:summary][:reason]
76
+ def fetch_matrix
77
+ Retry.while_error { pact_broker_client.matrix.get(version_selectors, matrix_options) }
74
78
  end
75
79
 
76
- def matrix
77
- @matrix ||= Retry.until_true { pact_broker_client.matrix.get(version_selectors, matrix_options) }
80
+ def fetch_matrix_with_retries
81
+ matrix = fetch_matrix
82
+ if retry_while_unknown?
83
+ check_if_retry_while_unknown_supported(matrix)
84
+ if matrix.any_unknown?
85
+ matrix = Retry.until_truthy_or_max_times(retry_options) do
86
+ fetch_matrix
87
+ end
88
+ end
89
+ end
90
+ matrix
78
91
  end
79
92
 
80
93
  def pact_broker_client
81
94
  @pact_broker_client ||= PactBroker::Client::PactBrokerClient.new(base_url: pact_broker_base_url, client_options: pact_broker_client_options)
82
95
  end
96
+
97
+ def retry_while_unknown?
98
+ options[:retry_while_unknown] > 0
99
+ end
100
+
101
+ def retry_options
102
+ {
103
+ condition: lambda { |matrix| !matrix.any_unknown? },
104
+ tries: retry_tries,
105
+ sleep: retry_interval,
106
+ sleep_first: true
107
+ }
108
+ end
109
+
110
+ def retry_interval
111
+ options[:retry_interval]
112
+ end
113
+
114
+ def retry_tries
115
+ options[:retry_while_unknown]
116
+ end
117
+
118
+ def check_if_retry_while_unknown_supported(matrix)
119
+ if !matrix.supports_unknown_count?
120
+ raise PactBroker::Client::Error.new("This version of the Pact Broker does not provide a count of the unknown verification results. Please upgrade your Broker to >= v2.23.4")
121
+ end
122
+ end
83
123
  end
84
124
  end
85
125
  end
@@ -29,11 +29,14 @@ module PactBroker
29
29
  method_option :broker_password, aliases: "-p", desc: "Pact Broker basic auth password"
30
30
  method_option :output, aliases: "-o", desc: "json or table", default: 'table'
31
31
  method_option :verbose, aliases: "-v", type: :boolean, default: false, required: false, desc: "Verbose output. Default: false"
32
+ 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)"
33
+ method_option :retry_interval, banner: 'SECONDS', type: :numeric, default: 10, required: false, desc: "The time between retries in seconds. Use in conjuction with --retry-while-unknown"
32
34
 
33
35
  def can_i_deploy(*ignored_but_necessary)
34
36
  selectors = VersionSelectorOptionsParser.call(ARGV)
35
37
  validate_can_i_deploy_selectors(selectors)
36
- result = CanIDeploy.call(options.broker_base_url, selectors, {to_tag: options.to}, {output: options.output}, pact_broker_client_options)
38
+ can_i_deploy_options = { output: options.output, retry_while_unknown: options.retry_while_unknown, retry_interval: options.retry_interval }
39
+ result = CanIDeploy.call(options.broker_base_url, selectors, {to_tag: options.to}, can_i_deploy_options, pact_broker_client_options)
37
40
  $stdout.puts result.message
38
41
  exit(1) unless result.success
39
42
  end
@@ -31,7 +31,7 @@ module PactBroker
31
31
  tags.each do | tag |
32
32
  # todo check that pacticipant exists first
33
33
  $stdout.puts "Tagging #{pacticipant_name} version #{version} as #{tag}"
34
- Retry.until_true do
34
+ Retry.while_error do
35
35
  pact_broker_client.pacticipants.versions.tag pacticipant: pacticipant_name, version: version, tag: tag
36
36
  end
37
37
  end
@@ -43,7 +43,7 @@ module PactBroker
43
43
  end
44
44
 
45
45
  def perform_request request, uri
46
- response = Retry.until_true do
46
+ response = Retry.while_error do
47
47
  http = Net::HTTP.new(uri.host, uri.port, :ENV)
48
48
  http.set_debug_output($stderr) if verbose
49
49
  http.use_ssl = (uri.scheme == 'https')
@@ -1,4 +1,5 @@
1
1
  require_relative 'base_client'
2
+ require 'pact_broker/client/matrix/resource'
2
3
 
3
4
  module PactBroker
4
5
  module Client
@@ -11,7 +12,7 @@ module PactBroker
11
12
  }.merge(query_options(options))
12
13
  response = self.class.get("/matrix", query: query, headers: default_get_headers)
13
14
  response = handle_response(response) do
14
- JSON.parse(response.body, symbolize_names: true)
15
+ Matrix::Resource.new(JSON.parse(response.body, symbolize_names: true))
15
16
  end
16
17
  end
17
18
 
@@ -21,7 +22,7 @@ module PactBroker
21
22
  elsif response.code == 401
22
23
  raise Error.new("Authentication failed")
23
24
  elsif response.code == 404
24
- raise Error.new("Matrix resource not found at #{base_url}/matrix. Please upgrade your broker to the latest version.")
25
+ raise Error.new("Matrix resource not found at #{base_url}/matrix. Please upgrade your Broker to the latest version.")
25
26
  else
26
27
  error_message = nil
27
28
  begin
@@ -0,0 +1,34 @@
1
+ require 'pact_broker/client/base_client'
2
+
3
+ module PactBroker
4
+ module Client
5
+ class Matrix < BaseClient
6
+ class Resource < Hash
7
+
8
+ def initialize hash
9
+ self.merge!(hash)
10
+ end
11
+
12
+ def any_unknown?
13
+ if supports_unknown_count?
14
+ self[:summary][:unknown] > 0
15
+ else
16
+ false
17
+ end
18
+ end
19
+
20
+ def supports_unknown_count?
21
+ !!(self[:summary] && Integer === self[:summary][:unknown] )
22
+ end
23
+
24
+ def reason
25
+ self[:summary][:reason]
26
+ end
27
+
28
+ def deployable?
29
+ self[:summary][:deployable]
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -71,7 +71,7 @@ module PactBroker
71
71
 
72
72
  def tag_consumer_version tag
73
73
  versions = pact_broker_client.pacticipants.versions
74
- Retry.until_true do
74
+ Retry.while_error do
75
75
  $stdout.puts "Tagging version #{consumer_version} of #{consumer_name} as #{tag.inspect}"
76
76
  versions.tag(pacticipant: consumer_name, version: consumer_version, tag: tag)
77
77
  true
@@ -82,7 +82,7 @@ module PactBroker
82
82
  end
83
83
 
84
84
  def publish_pact_contents(pact)
85
- Retry.until_true do
85
+ Retry.while_error do
86
86
  pacts = pact_broker_client.pacticipants.versions.pacts
87
87
  if pacts.version_published?(consumer: pact.consumer_name, provider: pact.provider_name, consumer_version: consumer_version)
88
88
  $stdout.puts ::Term::ANSIColor.yellow("The given version of pact is already published. Overwriting...")
@@ -14,7 +14,7 @@ module PactBroker
14
14
  end
15
15
  end
16
16
 
17
- def self.until_true options = {}
17
+ def self.while_error options = {}
18
18
  max_tries = options.fetch(:times, 3)
19
19
  tries = 0
20
20
  while true
@@ -24,13 +24,41 @@ module PactBroker
24
24
  tries += 1
25
25
  $stderr.puts "Error making request - #{e.class} #{e.message} #{e.backtrace.find{|l| l.include?('pact_broker-client')}}, attempt #{tries} of #{max_tries}"
26
26
  raise e if max_tries == tries
27
- sleep options
27
+ sleep options.fetch(:sleep, 5)
28
28
  end
29
29
  end
30
30
  end
31
31
 
32
- def self.sleep options
33
- Kernel.sleep options.fetch(:sleep, 5)
32
+ def self.until_truthy_or_max_times options = {}
33
+ max_tries = options.fetch(:times, 3)
34
+ tries = 0
35
+ verbose = options[:verbose]
36
+ sleep_interval = options.fetch(:sleep, 5)
37
+ sleep(sleep_interval) if options[:sleep_first]
38
+ while true
39
+ begin
40
+ result = yield
41
+ return result if max_tries < 2
42
+ if options[:condition]
43
+ condition_result = options[:condition].call(result)
44
+ return result if condition_result
45
+ else
46
+ return result if result
47
+ end
48
+ tries += 1
49
+ return result if max_tries == tries
50
+ sleep sleep_interval
51
+ rescue RescuableError => e
52
+ tries += 1
53
+ $stderr.puts "ERROR: Error making request - #{e.class} #{e.message} #{e.backtrace.find{|l| l.include?('pact_broker-client')}}, attempt #{tries} of #{max_tries}"
54
+ raise e if max_tries == tries
55
+ sleep sleep_interval
56
+ end
57
+ end
58
+ end
59
+
60
+ def self.sleep seconds
61
+ Kernel.sleep seconds
34
62
  end
35
63
  end
36
64
  end
@@ -1,5 +1,5 @@
1
1
  module PactBroker
2
2
  module Client
3
- VERSION = '1.15.1'
3
+ VERSION = '1.16.0'
4
4
  end
5
5
  end
@@ -9,7 +9,7 @@ module PactBroker
9
9
  module Webhooks
10
10
  class Create
11
11
 
12
- WEBHOOKS_WITH_OPTIONAL_PACTICICPANTS_NOT_SUPPORTED = "Your version of the Pact Broker requires that both consumer and provider are specified for a webhook. Please upgrade your broker to >= 2.22.0 to create a webhook with optional consumer and provider."
12
+ WEBHOOKS_WITH_OPTIONAL_PACTICICPANTS_NOT_SUPPORTED = "This version of the Pact Broker requires that both consumer and provider are specified for a webhook. Please upgrade your broker to >= 2.22.0 to create a webhook with optional consumer and provider."
13
13
 
14
14
  attr_reader :params, :pact_broker_base_url, :basic_auth_options, :verbose
15
15
 
@@ -1,4 +1,5 @@
1
1
  require 'pact_broker/client/can_i_deploy'
2
+ require 'pact_broker/client/matrix/resource'
2
3
 
3
4
  module PactBroker
4
5
  module Client
@@ -8,8 +9,12 @@ module PactBroker
8
9
  let(:matrix_options) { {} }
9
10
  let(:pact_broker_client_options) { { foo: 'bar' } }
10
11
  let(:matrix_client) { instance_double('PactBroker::Client::Matrix') }
11
- let(:matrix) { { matrix: ['foo'], summary: { deployable: true, reason: 'some reason' } } }
12
- let(:options) { { output: 'text' } }
12
+ let(:matrix) { instance_double('Matrix::Resource', deployable?: true, reason: 'some reason', any_unknown?: any_unknown, supports_unknown_count?: supports_unknown_count) }
13
+ let(:any_unknown) { false }
14
+ let(:supports_unknown_count) { true }
15
+ let(:retry_while_unknown) { 0 }
16
+ let(:options) { { output: 'text', retry_while_unknown: retry_while_unknown, retry_interval: 5} }
17
+
13
18
 
14
19
  before do
15
20
  allow_any_instance_of(PactBroker::Client::PactBrokerClient).to receive(:matrix).and_return(matrix_client)
@@ -29,7 +34,7 @@ module PactBroker
29
34
  subject
30
35
  end
31
36
 
32
- context "when compatible versions are found" do
37
+ context "when the versions are deployable" do
33
38
  it "returns a success response" do
34
39
  expect(subject.success).to be true
35
40
  end
@@ -44,8 +49,8 @@ module PactBroker
44
49
  end
45
50
  end
46
51
 
47
- context "when compatible versions are not found" do
48
- let(:matrix) { {matrix: ['foo'], summary: { deployable: false, reason: 'some reason' }} }
52
+ context "when the versions are not deployable" do
53
+ let(:matrix) { instance_double('Matrix::Resource', deployable?: false, reason: 'some reason', any_unknown?: false) }
49
54
 
50
55
  it "returns a failure response" do
51
56
  expect(subject.success).to be false
@@ -60,6 +65,38 @@ module PactBroker
60
65
  end
61
66
  end
62
67
 
68
+ context "when retry_while_unknown is greater than 0" do
69
+ let(:retry_while_unknown) { 1 }
70
+
71
+ context "when any_unknown? is false" do
72
+ it "does not retry the request" do
73
+ expect(Retry).to_not receive(:until_truthy_or_max_times)
74
+ subject
75
+ end
76
+ end
77
+
78
+ context "when any_unknown? is true" do
79
+ let(:any_unknown) { true }
80
+
81
+ it "retries the request" do
82
+ expect(Retry).to receive(:until_truthy_or_max_times).with(hash_including(tries: 1, sleep: 5, sleep_first: true))
83
+ subject
84
+ end
85
+ end
86
+
87
+ context "when the matrix does not support the unknown count" do
88
+ let(:supports_unknown_count) { false }
89
+
90
+ it "returns a failure response" do
91
+ expect(subject.success).to be false
92
+ end
93
+
94
+ it "returns a failure message" do
95
+ expect(subject.message).to match /does not provide a count/
96
+ end
97
+ end
98
+ end
99
+
63
100
  context "when a PactBroker::Client::Error is raised" do
64
101
  before do
65
102
  allow(matrix_client).to receive(:get).and_raise(PactBroker::Client::Error.new('error text'))
@@ -76,7 +113,7 @@ module PactBroker
76
113
 
77
114
  context "when a StandardError is raised" do
78
115
  before do
79
- allow(Retry).to receive(:until_true) { |&block| block.call }
116
+ allow(Retry).to receive(:while_error) { |&block| block.call }
80
117
  allow($stderr).to receive(:puts)
81
118
  allow(matrix_client).to receive(:get).and_raise(StandardError.new('error text'))
82
119
  end
@@ -20,7 +20,9 @@ module PactBroker
20
20
  {
21
21
  broker_base_url: 'http://pact-broker',
22
22
  output: 'table',
23
- verbose: 'verbose'
23
+ verbose: 'verbose',
24
+ retry_while_unknown: 1,
25
+ retry_interval: 2
24
26
  }
25
27
  end
26
28
 
@@ -32,7 +34,7 @@ module PactBroker
32
34
  end
33
35
 
34
36
  it "invokes the CanIDeploy service" do
35
- expect(CanIDeploy).to receive(:call).with('http://pact-broker', version_selectors, {to_tag: nil}, {output: 'table'}, {verbose: 'verbose'})
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'})
36
38
  invoke_can_i_deploy
37
39
  end
38
40
 
@@ -4,7 +4,7 @@ module PactBroker::Client
4
4
  module Hal
5
5
  describe HttpClient do
6
6
  before do
7
- allow(Retry).to receive(:until_true) { |&block| block.call }
7
+ allow(Retry).to receive(:while_error) { |&block| block.call }
8
8
  end
9
9
 
10
10
  subject { HttpClient.new(username: 'foo', password: 'bar') }
@@ -43,7 +43,7 @@ module PactBroker::Client
43
43
 
44
44
 
45
45
  it "retries on failure" do
46
- expect(Retry).to receive(:until_true)
46
+ expect(Retry).to receive(:while_error)
47
47
  do_get
48
48
  end
49
49
 
@@ -74,8 +74,8 @@ module PactBroker::Client
74
74
  expect(request).to have_been_made
75
75
  end
76
76
 
77
- it "calls Retry.until_true" do
78
- expect(Retry).to receive(:until_true)
77
+ it "calls Retry.while_error" do
78
+ expect(Retry).to receive(:while_error)
79
79
  do_post
80
80
  end
81
81
 
@@ -0,0 +1,70 @@
1
+ require 'pact_broker/client/matrix/resource'
2
+
3
+ module PactBroker
4
+ module Client
5
+ class Matrix
6
+ describe Resource do
7
+
8
+ let(:matrix_hash) { JSON.parse(File.read('spec/support/matrix.json'), symbolize_names: true) }
9
+
10
+ subject { Resource.new(matrix_hash) }
11
+
12
+ describe "any_unknown?" do
13
+ context "when $summary.unknown is greater than 0" do
14
+ it "is true" do
15
+ expect(subject.any_unknown?).to be true
16
+ end
17
+ end
18
+
19
+ context "when $summary.unknown is 0" do
20
+ before do
21
+ matrix_hash[:summary][:unknown] = 0
22
+ end
23
+
24
+ it "is false" do
25
+ expect(subject.any_unknown?).to be false
26
+ end
27
+ end
28
+ end
29
+
30
+ describe "supports_unknown_count?" do
31
+ context "when $summary.unknown is present" do
32
+ it "is true" do
33
+ expect(subject.supports_unknown_count?).to be true
34
+ end
35
+ end
36
+
37
+ context "when $summary.unknown is nil" do
38
+ before do
39
+ matrix_hash[:summary][:unknown] = nil
40
+ end
41
+
42
+ it "is false" do
43
+ expect(subject.supports_unknown_count?).to be false
44
+ end
45
+ end
46
+
47
+ context "when $summary.unknown is not an Integer" do
48
+ before do
49
+ matrix_hash[:summary][:unknown] = true
50
+ end
51
+
52
+ it "is false" do
53
+ expect(subject.supports_unknown_count?).to be false
54
+ end
55
+ end
56
+
57
+ context "when $summary.unknown is not present" do
58
+ before do
59
+ matrix_hash[:summary].delete(:unknown)
60
+ end
61
+
62
+ it "is false" do
63
+ expect(subject.supports_unknown_count?).to be false
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,119 @@
1
+ require 'pact_broker/client/retry'
2
+
3
+ module PactBroker
4
+ module Client
5
+ describe Retry do
6
+ describe ".until_truthy_or_max_times" do
7
+ before do
8
+ allow(service).to receive(:get_result).and_return(1, 2, 3)
9
+ allow(condition).to receive(:call).and_return(false, false, true)
10
+ allow(Retry).to receive(:sleep)
11
+ end
12
+
13
+ let(:service) { double('service') }
14
+ let(:condition) { double('condition') }
15
+ let(:times) { 4 }
16
+ let(:sleep_first) { nil }
17
+
18
+ subject do
19
+ Retry.until_truthy_or_max_times(condition: condition, times: times, sleep: 3, sleep_first: sleep_first) do
20
+ service.get_result
21
+ end
22
+ end
23
+
24
+ context "times is 0 (which it shouldn't be, but just to be sure...)" do
25
+ let(:times) { 0 }
26
+
27
+ it "only executes the block once" do
28
+ subject
29
+ expect(service).to have_received(:get_result).exactly(1).times
30
+ end
31
+
32
+ it "does not execute the condition" do
33
+ expect(condition).to_not receive(:call)
34
+ subject
35
+ end
36
+
37
+ it "returns the result" do
38
+ expect(subject).to eq 1
39
+ end
40
+ end
41
+
42
+ context "times is 1" do
43
+ let(:times) { 1 }
44
+
45
+ it "only executes the block once" do
46
+ subject
47
+ expect(service).to have_received(:get_result).exactly(1).times
48
+ end
49
+
50
+ it "does not execute the condition" do
51
+ expect(condition).to_not receive(:call)
52
+ subject
53
+ end
54
+
55
+ it "returns the result" do
56
+ expect(subject).to eq 1
57
+ end
58
+ end
59
+
60
+ context "when the condition becomes true before the max tries" do
61
+ it "stops retrying when the condition becomes true" do
62
+ subject
63
+ expect(condition).to have_received(:call).exactly(3).times
64
+ expect(service).to have_received(:get_result).exactly(3).times
65
+ end
66
+
67
+ it "returns the most recent result" do
68
+ expect(subject).to eq 3
69
+ end
70
+ end
71
+
72
+ context "when the max tries is reached before the condition becomes true" do
73
+ let(:times) { 2 }
74
+
75
+ it "stops retrying once the max tries is reached" do
76
+ subject
77
+ expect(condition).to have_received(:call).exactly(2).times
78
+ expect(service).to have_received(:get_result).exactly(2).times
79
+ end
80
+
81
+ it "returns the most recent result" do
82
+ expect(subject).to eq 2
83
+ end
84
+ end
85
+
86
+ context "when an error is raised each time" do
87
+ TestError = Class.new(StandardError)
88
+
89
+ before do
90
+ allow(service).to receive(:get_result).and_raise(TestError)
91
+ allow($stderr).to receive(:puts)
92
+ end
93
+
94
+ it "stops retrying once the max tries is reached" do
95
+ begin
96
+ subject
97
+ rescue TestError
98
+ end
99
+ expect(service).to have_received(:get_result).exactly(4).times
100
+ end
101
+
102
+ it "raises the error" do
103
+ expect { subject }.to raise_error TestError
104
+ end
105
+ end
106
+
107
+ context "when sleep_first is true" do
108
+ let(:sleep_first) { true }
109
+
110
+ it "sleeps before it executes the block" do
111
+ expect(Retry).to receive(:sleep).ordered
112
+ expect(service).to receive(:get_result).ordered
113
+ subject
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
119
+ end
@@ -39,7 +39,7 @@ module PactBroker
39
39
  context "when a 405 is returned from the webhook creation request" do
40
40
 
41
41
  it "raises an error with a message to upgrade the Pact Broker" do
42
- expect { subject }.to raise_error PactBroker::Client::Error, /Your version of the Pact Broker/
42
+ expect { subject }.to raise_error PactBroker::Client::Error, /This version of the Pact Broker/
43
43
  end
44
44
  end
45
45
 
@@ -202,7 +202,8 @@
202
202
  "body": {
203
203
  "summary": {
204
204
  "deployable": true,
205
- "reason": "some text"
205
+ "reason": "some text",
206
+ "unknown": 1
206
207
  },
207
208
  "matrix": [
208
209
  {
@@ -251,7 +252,8 @@
251
252
  "body": {
252
253
  "summary": {
253
254
  "deployable": true,
254
- "reason": "some text"
255
+ "reason": "some text",
256
+ "unknown": 1
255
257
  },
256
258
  "matrix": [
257
259
  {
@@ -300,7 +302,8 @@
300
302
  "body": {
301
303
  "summary": {
302
304
  "deployable": true,
303
- "reason": "some text"
305
+ "reason": "some text",
306
+ "unknown": 1
304
307
  },
305
308
  "matrix": [
306
309
  {
@@ -473,7 +476,8 @@
473
476
  "body": {
474
477
  "summary": {
475
478
  "deployable": true,
476
- "reason": "some text"
479
+ "reason": "some text",
480
+ "unknown": 1
477
481
  },
478
482
  "matrix": [
479
483
  {
@@ -522,7 +526,8 @@
522
526
  "body": {
523
527
  "summary": {
524
528
  "deployable": true,
525
- "reason": "some text"
529
+ "reason": "some text",
530
+ "unknown": 1
526
531
  },
527
532
  "matrix": [
528
533
  {
@@ -571,7 +576,8 @@
571
576
  "body": {
572
577
  "summary": {
573
578
  "deployable": true,
574
- "reason": "some text"
579
+ "reason": "some text",
580
+ "unknown": 1
575
581
  },
576
582
  "matrix": [
577
583
  {
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "summary": {
3
3
  "deployable": true,
4
- "reason": "some text"
4
+ "reason": "some text",
5
+ "unknown": 1
5
6
  },
6
7
  "matrix": [
7
8
  {
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.15.1
4
+ version: 1.16.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: 2018-06-27 00:00:00.000000000 Z
11
+ date: 2018-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -214,6 +214,7 @@ files:
214
214
  - lib/pact_broker/client/matrix.rb
215
215
  - lib/pact_broker/client/matrix/formatter.rb
216
216
  - lib/pact_broker/client/matrix/json_formatter.rb
217
+ - lib/pact_broker/client/matrix/resource.rb
217
218
  - lib/pact_broker/client/matrix/text_formatter.rb
218
219
  - lib/pact_broker/client/merge_pacts.rb
219
220
  - lib/pact_broker/client/pact_broker_client.rb
@@ -249,12 +250,14 @@ files:
249
250
  - spec/lib/pact_broker/client/hal/entity_spec.rb
250
251
  - spec/lib/pact_broker/client/hal/http_client_spec.rb
251
252
  - spec/lib/pact_broker/client/hal/link_spec.rb
253
+ - spec/lib/pact_broker/client/matrix/resource_spec.rb
252
254
  - spec/lib/pact_broker/client/matrix/text_formatter_spec.rb
253
255
  - spec/lib/pact_broker/client/matrix_spec.rb
254
256
  - spec/lib/pact_broker/client/merge_pacts_spec.rb
255
257
  - spec/lib/pact_broker/client/pact_broker_client_spec.rb
256
258
  - spec/lib/pact_broker/client/pacticipants_spec.rb
257
259
  - spec/lib/pact_broker/client/publish_pacts_spec.rb
260
+ - spec/lib/pact_broker/client/retry_spec.rb
258
261
  - spec/lib/pact_broker/client/tasks/publication_task_spec.rb
259
262
  - spec/lib/pact_broker/client/versions/describe_spec.rb
260
263
  - spec/lib/pact_broker/client/versions_spec.rb
@@ -320,12 +323,14 @@ test_files:
320
323
  - spec/lib/pact_broker/client/hal/entity_spec.rb
321
324
  - spec/lib/pact_broker/client/hal/http_client_spec.rb
322
325
  - spec/lib/pact_broker/client/hal/link_spec.rb
326
+ - spec/lib/pact_broker/client/matrix/resource_spec.rb
323
327
  - spec/lib/pact_broker/client/matrix/text_formatter_spec.rb
324
328
  - spec/lib/pact_broker/client/matrix_spec.rb
325
329
  - spec/lib/pact_broker/client/merge_pacts_spec.rb
326
330
  - spec/lib/pact_broker/client/pact_broker_client_spec.rb
327
331
  - spec/lib/pact_broker/client/pacticipants_spec.rb
328
332
  - spec/lib/pact_broker/client/publish_pacts_spec.rb
333
+ - spec/lib/pact_broker/client/retry_spec.rb
329
334
  - spec/lib/pact_broker/client/tasks/publication_task_spec.rb
330
335
  - spec/lib/pact_broker/client/versions/describe_spec.rb
331
336
  - spec/lib/pact_broker/client/versions_spec.rb