pact_broker 2.23.3 → 2.23.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (27) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -0
  3. data/lib/pact_broker/api/decorators/matrix_decorator.rb +12 -17
  4. data/lib/pact_broker/api/decorators/provider_pacts_decorator.rb +10 -2
  5. data/lib/pact_broker/api/resources.rb +4 -2
  6. data/lib/pact_broker/api/resources/relationships.rb +1 -3
  7. data/lib/pact_broker/matrix/deployment_status_summary.rb +89 -0
  8. data/lib/pact_broker/matrix/integration.rb +54 -0
  9. data/lib/pact_broker/matrix/parse_query.rb +1 -1
  10. data/lib/pact_broker/matrix/query_results.rb +18 -0
  11. data/lib/pact_broker/matrix/query_results_with_deployment_status_summary.rb +14 -0
  12. data/lib/pact_broker/matrix/repository.rb +32 -20
  13. data/lib/pact_broker/matrix/service.rb +10 -3
  14. data/lib/pact_broker/verifications/repository.rb +4 -0
  15. data/lib/pact_broker/version.rb +1 -1
  16. data/lib/pact_broker/versions/service.rb +1 -0
  17. data/spec/lib/pact_broker/api/decorators/matrix_decorator_spec.rb +22 -47
  18. data/spec/lib/pact_broker/api/decorators/provider_pacts_decorator_spec.rb +5 -4
  19. data/spec/lib/pact_broker/matrix/deployment_status_summary_spec.rb +98 -0
  20. data/spec/lib/pact_broker/matrix/parse_query_spec.rb +8 -0
  21. data/spec/lib/pact_broker/matrix/repository_find_integrations_spec.rb +51 -0
  22. data/spec/lib/pact_broker/matrix/repository_spec.rb +24 -0
  23. data/spec/lib/pact_broker/matrix/service_spec.rb +26 -0
  24. data/spec/lib/pact_broker/verifications/repository_spec.rb +20 -0
  25. data/spec/lib/pact_broker/versions/service_spec.rb +9 -1
  26. data/spec/support/test_data_builder.rb +4 -2
  27. metadata +10 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5320609fbb367f2ffabec8627e24c378ae83e5e5
4
- data.tar.gz: fccd5a3dc7c31d99010e69506dc4e6c63b34e03e
3
+ metadata.gz: 7bd5ebfd2122389ceccb3515386666e4152c57a4
4
+ data.tar.gz: fb9817503a5f8762b7d79092abc6a7b34cf10027
5
5
  SHA512:
6
- metadata.gz: 342a5c332caf6276eddd67a4675c8f710e88901372e3fc9805ac4059ceabd0c9f0801f43da1cd4cfd33bd028c823375f9d2e7e7d764295d892016baafea88b97
7
- data.tar.gz: 717bf69efdafc7b8901b38c24ddc0c4afd3d19de5f49be94135fbe4b9687597e3cb6a70c13945ed3addea64f0d67293df7c0d900fe18f08de938e1f07e8fba71
6
+ metadata.gz: a4a893b1fc19db8c348e700f2d267828c39ee8eaba41ce8e9d97101f8b7e1f7e0a1d6c5269a53ccf34737cb14b0fe5dcd450c1a02a788bad77cbdcd3ecb47a83
7
+ data.tar.gz: 0c575437f3cb2ab677a22ca8d6d29849fc5033ea2028b887c8fe6a151a06222909d81fa22146ce8fba225230fb440cae381d3845900dd1cf120db11d4cf87242
data/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ <a name="v2.23.4"></a>
2
+ ### v2.23.4 (2018-07-04)
3
+
4
+
5
+ #### Features
6
+
7
+ * deprecate provider relation in provider pacts resource in preference for pb:provider ([eda8cbf](/../../commit/eda8cbf))
8
+
9
+
10
+ #### Bug Fixes
11
+
12
+ * correct the logic for determining the deployment status in the matrix resource ([ad85db4](/../../commit/ad85db4))
13
+ * delete associated verification results when a pacticipant version is deleted ([ddec810](/../../commit/ddec810))
14
+
15
+
1
16
  <a name="v2.23.3"></a>
2
17
  ### v2.23.3 (2018-06-27)
3
18
 
@@ -7,8 +7,8 @@ module PactBroker
7
7
  class MatrixDecorator
8
8
  include PactBroker::Api::PactBrokerUrls
9
9
 
10
- def initialize(lines)
11
- @lines = lines
10
+ def initialize(query_results_with_deployment_status_summary)
11
+ @query_results_with_deployment_status_summary = query_results_with_deployment_status_summary
12
12
  end
13
13
 
14
14
  def to_json(options)
@@ -21,32 +21,27 @@ module PactBroker
21
21
  deployable: deployable,
22
22
  reason: reason
23
23
  },
24
- matrix: matrix(lines, options[:user_options][:base_url])
25
- }
24
+ matrix: matrix(options[:user_options][:base_url])
25
+ }.tap do | hash |
26
+ hash[:summary].merge!(query_results_with_deployment_status_summary.deployment_status_summary.counts)
27
+ end
28
+
26
29
  end
27
30
 
28
31
  def deployable
29
- return nil if lines.empty?
30
- return nil if lines.any?{ |line| line.success.nil? }
31
- lines.any? && lines.all?{ |line| line.success }
32
+ query_results_with_deployment_status_summary.deployment_status_summary.deployable?
32
33
  end
33
34
 
34
35
  def reason
35
- return "No results matched the given query" if lines.empty?
36
- case deployable
37
- when true then "All verification results are published and successful"
38
- when false then "One or more verifications have failed"
39
- else
40
- "Missing one or more verification results"
41
- end
36
+ query_results_with_deployment_status_summary.deployment_status_summary.reasons.join("\n")
42
37
  end
43
38
 
44
39
  private
45
40
 
46
- attr_reader :lines
41
+ attr_reader :query_results_with_deployment_status_summary
47
42
 
48
- def matrix(lines, base_url)
49
- lines.collect do | line |
43
+ def matrix(base_url)
44
+ query_results_with_deployment_status_summary.rows.collect do | line |
50
45
  provider = OpenStruct.new(name: line.provider_name)
51
46
  consumer = OpenStruct.new(name: line.consumer_name)
52
47
  consumer_version = OpenStruct.new(number: line.consumer_version_number, pacticipant: consumer)
@@ -14,10 +14,10 @@ module PactBroker
14
14
  }
15
15
  end
16
16
 
17
- link :provider do | context |
17
+ link :'pb:provider' do | context |
18
18
  {
19
19
  href: pacticipant_url(context[:base_url], OpenStruct.new(name: context[:provider_name])),
20
- title: context[:provider_name]
20
+ name: context[:provider_name]
21
21
  }
22
22
  end
23
23
 
@@ -32,6 +32,14 @@ module PactBroker
32
32
  end
33
33
  end
34
34
 
35
+ link :provider do | context |
36
+ {
37
+ href: pacticipant_url(context[:base_url], OpenStruct.new(name: context[:provider_name])),
38
+ title: context[:provider_name],
39
+ name: "DEPRECATED - please use the pb:provider relation"
40
+ }
41
+ end
42
+
35
43
  links :'pacts' do | context |
36
44
  represented.collect do | pact |
37
45
  {
@@ -5,6 +5,8 @@ Reform::Form.class_eval do
5
5
  feature Reform::Form::Dry
6
6
  end
7
7
 
8
- Dir.glob(File.expand_path(File.join(__FILE__, "..", "resources", "*.rb"))) do |file|
9
- require file
8
+ require 'pact_broker/api/resources/base_resource'
9
+
10
+ Dir.glob(File.expand_path(File.join(__FILE__, "..", "resources", "*.rb"))).sort.each do | path |
11
+ require path
10
12
  end
@@ -22,9 +22,7 @@ module PactBroker
22
22
  def pacts
23
23
  pact_service.find_latest_pacts
24
24
  end
25
-
26
25
  end
27
26
  end
28
-
29
27
  end
30
- end
28
+ end
@@ -0,0 +1,89 @@
1
+ module PactBroker
2
+ module Matrix
3
+ class DeploymentStatusSummary
4
+ attr_reader :rows, :resolved_selectors, :integrations
5
+
6
+ def initialize(rows, resolved_selectors, integrations)
7
+ @rows = rows
8
+ @resolved_selectors = resolved_selectors
9
+ @integrations = integrations
10
+ end
11
+
12
+ def counts
13
+ {
14
+ success: rows.count{ |row| row.success },
15
+ failed: rows.count { |row| row.success == false },
16
+ unknown: integrations_without_a_row.count + rows.count { |row| row.success.nil? }
17
+ }
18
+ end
19
+
20
+ def deployable?
21
+ return nil if rows.empty?
22
+ return nil if rows.any?{ |row| row.success.nil? }
23
+ return nil if integrations_without_a_row.any?
24
+ rows.all?{ |row| row.success }
25
+ end
26
+
27
+ def reasons
28
+ @reasons ||= begin
29
+ reasons = []
30
+ if rows.empty?
31
+ reasons << "No results matched the given query"
32
+ else
33
+ reasons.concat(missing_reasons)
34
+ reasons.concat(failure_messages)
35
+ reasons.concat(unverified_messages)
36
+ reasons.concat(success_messages)
37
+ end
38
+ reasons
39
+ end
40
+ end
41
+
42
+ def unverified_messages
43
+ if rows.any?{ |row| row.success.nil? }
44
+ ["Missing one or more verification results"]
45
+ else
46
+ []
47
+ end
48
+ end
49
+
50
+ def failure_messages
51
+ if rows.any?{ |row| row.success == false }
52
+ ["One or more verifications have failed"]
53
+ else
54
+ []
55
+ end
56
+ end
57
+
58
+ def success_messages
59
+ if rows.all?{ |row| row.success } && integrations_without_a_row.empty?
60
+ ["All verification results are published and successful"]
61
+ else
62
+ []
63
+ end
64
+ end
65
+
66
+ def integrations_without_a_row
67
+ @integrations_without_a_row ||= begin
68
+ integrations.select do | relationship |
69
+ !rows.find do | row |
70
+ row.consumer_id == relationship.consumer_id && row.provider_id == relationship.provider_id
71
+ end
72
+ end
73
+ end
74
+ end
75
+
76
+ def missing_reasons
77
+ integrations_without_a_row.collect do | missing_relationship|
78
+ consumer_version_desc = "#{missing_relationship.consumer_name} (#{resolved_version_for(missing_relationship.consumer_id)})"
79
+ provider_version_desc = "#{missing_relationship.provider_name} (#{resolved_version_for(missing_relationship.provider_id)})"
80
+ "There is no verified pact between #{consumer_version_desc} and #{provider_version_desc}"
81
+ end
82
+ end
83
+
84
+ def resolved_version_for(pacticipant_id)
85
+ resolved_selectors.find{ | s| s[:pacticipant_id] == pacticipant_id }[:pacticipant_version_number]
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,54 @@
1
+ #
2
+ # Represents the integration relationship between a consumer and a provider
3
+ #
4
+ module PactBroker
5
+ module Matrix
6
+ class Integration
7
+
8
+ attr_reader :consumer_name, :consumer_id, :provider_name, :provider_id
9
+
10
+ def initialize consumer_id, consumer_name, provider_id, provider_name
11
+ @consumer_id = consumer_id
12
+ @consumer_name = consumer_name
13
+ @provider_id = provider_id
14
+ @provider_name = provider_name
15
+ end
16
+
17
+ def self.from_hash hash
18
+ new(
19
+ hash.fetch(:consumer_id),
20
+ hash.fetch(:consumer_name),
21
+ hash.fetch(:provider_id),
22
+ hash.fetch(:provider_name)
23
+ )
24
+ end
25
+
26
+ def == other
27
+ consumer_id == other.consumer_id && provider_id == other.provider_id
28
+ end
29
+
30
+ def <=> other
31
+ comparison = consumer_name <=> other.consumer_name
32
+ return comparison if comparison != 0
33
+ provider_name <=> other.provider_name
34
+ end
35
+
36
+ def to_hash
37
+ {
38
+ consumer_name: consumer_name,
39
+ consumer_id: consumer_id,
40
+ provider_name: provider_name,
41
+ provider_id: provider_id,
42
+ }
43
+ end
44
+
45
+ def pacticipant_names
46
+ [consumer_name, provider_name]
47
+ end
48
+
49
+ def to_s
50
+ "Relationship between #{consumer_name} (id=#{consumer_id}) and #{provider_name} (id=#{provider_id})"
51
+ end
52
+ end
53
+ end
54
+ end
@@ -29,7 +29,7 @@ module PactBroker
29
29
  options[:limit] = params['limit']
30
30
  end
31
31
  if params.key?('latest') && params['latest'] != ''
32
- options[:latest] = params['latest']
32
+ options[:latest] = params['latest'] == 'true'
33
33
  end
34
34
  if params.key?('tag') && params['tag'] != ''
35
35
  options[:tag] = params['tag']
@@ -0,0 +1,18 @@
1
+ module PactBroker
2
+ module Matrix
3
+ class QueryResults < Array
4
+ attr_reader :selectors, :options, :resolved_selectors
5
+
6
+ def initialize rows, selectors, options, resolved_selectors
7
+ super(rows)
8
+ @selectors = selectors
9
+ @resolved_selectors = resolved_selectors
10
+ @options = options
11
+ end
12
+
13
+ def rows
14
+ to_a
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,14 @@
1
+ require 'pact_broker/matrix/query_results'
2
+
3
+ module PactBroker
4
+ module Matrix
5
+ class QueryResultsWithDeploymentStatusSummary < QueryResults
6
+ attr_reader :deployment_status_summary
7
+
8
+ def initialize rows, selectors, options, resolved_selectors, deployment_status_summary
9
+ super(rows, selectors, options, resolved_selectors)
10
+ @deployment_status_summary = deployment_status_summary
11
+ end
12
+ end
13
+ end
14
+ end
@@ -2,7 +2,9 @@ require 'pact_broker/repositories/helpers'
2
2
  require 'pact_broker/matrix/row'
3
3
  require 'pact_broker/matrix/head_row'
4
4
  require 'pact_broker/error'
5
-
5
+ require 'pact_broker/matrix/query_results'
6
+ require 'pact_broker/matrix/integration'
7
+ require 'pact_broker/matrix/query_results_with_deployment_status_summary'
6
8
 
7
9
  module PactBroker
8
10
  module Matrix
@@ -65,7 +67,8 @@ module PactBroker
65
67
 
66
68
  # Return the latest matrix row (pact/verification) for each consumer_version_number/provider_version_number
67
69
  def find selectors, options = {}
68
- lines = query_matrix(resolve_selectors(selectors, options), options)
70
+ resolved_selectors = resolve_selectors(selectors, options)
71
+ lines = query_matrix(resolved_selectors, options)
69
72
  lines = apply_latestby(options, selectors, lines)
70
73
 
71
74
  # This needs to be done after the latestby, so can't be done in the db unless
@@ -74,9 +77,31 @@ module PactBroker
74
77
  lines = lines.select{ |l| options[:success].include?(l.success) }
75
78
  end
76
79
 
77
- lines.sort
80
+ QueryResults.new(lines.sort, selectors, options, resolved_selectors)
81
+ end
82
+
83
+ def find_for_consumer_and_provider pacticipant_1_name, pacticipant_2_name
84
+ selectors = [{ pacticipant_name: pacticipant_1_name }, { pacticipant_name: pacticipant_2_name }]
85
+ options = { latestby: 'cvpv' }
86
+ find(selectors, options)
87
+ end
88
+
89
+ def find_compatible_pacticipant_versions selectors
90
+ find(selectors, latestby: 'cvpv').select{|line| line.success }
91
+ end
92
+
93
+ def find_integrations(pacticipant_names)
94
+ selectors = pacticipant_names.collect{ | pacticipant_name | add_ids(pacticipant_name: pacticipant_name) }
95
+ Row
96
+ .select(:consumer_name, :consumer_id, :provider_name, :provider_id)
97
+ .matching_selectors(selectors)
98
+ .distinct
99
+ .all
100
+ .collect{ |row | Integration.from_hash(row.to_hash) }.uniq
78
101
  end
79
102
 
103
+ private
104
+
80
105
  def apply_latestby options, selectors, lines
81
106
  return lines unless options[:latestby]
82
107
  group_by_columns = case options[:latestby]
@@ -106,16 +131,6 @@ module PactBroker
106
131
  latest_revisions
107
132
  end
108
133
 
109
- def find_for_consumer_and_provider pacticipant_1_name, pacticipant_2_name
110
- selectors = [{ pacticipant_name: pacticipant_1_name }, { pacticipant_name: pacticipant_2_name }]
111
- options = { latestby: 'cvpv' }
112
- find(selectors, options)
113
- end
114
-
115
- def find_compatible_pacticipant_versions selectors
116
- find(selectors, latestby: 'cvpv').select{|line| line.success }
117
- end
118
-
119
134
  def query_matrix selectors, options
120
135
  query = view_for(options).select_all.matching_selectors(selectors)
121
136
  query = query.limit(options[:limit]) if options[:limit]
@@ -195,7 +210,7 @@ module PactBroker
195
210
  # eg. when checking to see if Foo version 2 can be deployed to prod,
196
211
  # need to look up all the 'partner' pacticipants, and determine their latest prod versions
197
212
  def apply_latest_and_tag_to_inferred_selectors(selectors, options)
198
- all_pacticipant_names = all_pacticipant_names_in_specified_matrix(selectors, options)
213
+ all_pacticipant_names = all_pacticipant_names_in_specified_matrix(selectors)
199
214
  specified_names = selectors.collect{ |s| s[:pacticipant_name] }
200
215
  inferred_names = all_pacticipant_names - specified_names
201
216
 
@@ -211,12 +226,9 @@ module PactBroker
211
226
  selectors + look_up_version_numbers(inferred_selectors, options)
212
227
  end
213
228
 
214
- def all_pacticipant_names_in_specified_matrix(selectors, options)
215
- query = view_for(options).select(:consumer_name, :provider_name)
216
- query = query.matching_selectors(selectors)
217
- query
218
- .all
219
- .collect{ | row | [row.consumer_name, row.provider_name] }
229
+ def all_pacticipant_names_in_specified_matrix(selectors)
230
+ find_integrations(selectors.collect{|s| s[:pacticipant_name]})
231
+ .collect(&:pacticipant_names)
220
232
  .flatten
221
233
  .uniq
222
234
  end
@@ -1,5 +1,6 @@
1
1
  require 'pact_broker/repositories'
2
2
  require 'pact_broker/matrix/row'
3
+ require 'pact_broker/matrix/deployment_status_summary'
3
4
 
4
5
  module PactBroker
5
6
  module Matrix
@@ -17,12 +18,18 @@ module PactBroker
17
18
  matrix_repository.refresh_tags(params, &block)
18
19
  end
19
20
 
20
- def find criteria, options = {}
21
- matrix_repository.find criteria, options
21
+ def find selectors, options = {}
22
+ query_results = matrix_repository.find selectors, options
23
+ pacticipant_names = selectors.collect{ | s| s[:pacticipant_name] }
24
+ integrations = matrix_repository.find_integrations(pacticipant_names)
25
+ deployment_status_summary = DeploymentStatusSummary.new(query_results.rows, query_results.resolved_selectors, integrations)
26
+ QueryResultsWithDeploymentStatusSummary.new(query_results.rows, query_results.selectors, query_results.options, query_results.resolved_selectors, deployment_status_summary)
22
27
  end
23
28
 
24
29
  def find_for_consumer_and_provider params
25
- matrix_repository.find_for_consumer_and_provider params[:consumer_name], params[:provider_name]
30
+ selectors = [{ pacticipant_name: params[:consumer_name] }, { pacticipant_name: params[:provider_name] }]
31
+ options = { latestby: 'cvpv' }
32
+ find(selectors, options)
26
33
  end
27
34
 
28
35
  def find_for_consumer_and_provider_with_tags params
@@ -98,6 +98,10 @@ module PactBroker
98
98
  ).limit(1).single_record
99
99
  end
100
100
 
101
+ def delete_by_provider_version_id version_id
102
+ PactBroker::Domain::Verification.where(provider_version_id: version_id).delete
103
+ end
104
+
101
105
  def pact_version_id_for pact
102
106
  PactBroker::Pacts::PactPublication.select(:pact_version_id).where(id: pact.id)
103
107
  end
@@ -1,3 +1,3 @@
1
1
  module PactBroker
2
- VERSION = '2.23.3'
2
+ VERSION = '2.23.4'
3
3
  end
@@ -22,6 +22,7 @@ module PactBroker
22
22
  def self.delete version
23
23
  tag_repository.delete_by_version_id version.id
24
24
  pact_repository.delete_by_version_id version.id
25
+ verification_repository.delete_by_provider_version_id version.id
25
26
  version_repository.delete_by_id version.id
26
27
  end
27
28
  end
@@ -1,4 +1,6 @@
1
1
  require 'pact_broker/api/decorators/matrix_decorator'
2
+ require 'pact_broker/matrix/query_results_with_deployment_status_summary'
3
+ require 'pact_broker/matrix/deployment_status_summary'
2
4
 
3
5
  module PactBroker
4
6
  module Api
@@ -7,9 +9,9 @@ module PactBroker
7
9
  describe "to_json" do
8
10
  let(:verification_date) { DateTime.new(2017, 12, 31) }
9
11
  let(:pact_created_at) { DateTime.new(2017, 1, 1) }
10
- let(:line_1_success) { true }
11
- let(:line_2_success) { true }
12
- let(:line_1) do
12
+ let(:row_1_success) { true }
13
+ let(:row_2_success) { true }
14
+ let(:row_1) do
13
15
  double('PactBroker::Matrix::Row',
14
16
  {
15
17
  consumer_name: "Consumer",
@@ -18,7 +20,7 @@ module PactBroker
18
20
  pact_created_at: pact_created_at,
19
21
  provider_version_number: "4.5.6",
20
22
  provider_name: "Provider",
21
- success: line_1_success,
23
+ success: row_1_success,
22
24
  verification_number: 1,
23
25
  verification_build_url: nil,
24
26
  verification_executed_at: verification_date
@@ -26,7 +28,7 @@ module PactBroker
26
28
  )
27
29
  end
28
30
 
29
- let(:line_2) do
31
+ let(:row_2) do
30
32
  double('PactBroker::Matrix::Row',
31
33
  {
32
34
  consumer_name: "Consumer",
@@ -35,7 +37,7 @@ module PactBroker
35
37
  pact_created_at: pact_created_at,
36
38
  provider_version_number: nil,
37
39
  provider_name: "Provider",
38
- success: line_2_success,
40
+ success: row_2_success,
39
41
  verification_number: nil,
40
42
  verification_build_url: nil,
41
43
  verification_executed_at: verification_date
@@ -99,8 +101,16 @@ module PactBroker
99
101
  }
100
102
  end
101
103
 
102
- let(:lines){ [line_1, line_2]}
103
- let(:json) { MatrixDecorator.new(lines).to_json(user_options: { base_url: 'http://example.org' }) }
104
+ let(:query_results){ PactBroker::Matrix::QueryResultsWithDeploymentStatusSummary.new([row_1, row_2], selectors, options, resolved_selectors, deployment_status_summary)}
105
+ let(:selectors) { nil }
106
+ let(:options) { nil }
107
+ let(:resolved_selectors) { nil }
108
+ let(:counts) { { success: 1 } }
109
+ let(:deployment_status_summary) do
110
+ instance_double('PactBroker::Matrix::DeploymentStatusSummary', reasons: ['foo', 'bar'], deployable?: deployable, counts: counts)
111
+ end
112
+ let(:deployable) { true }
113
+ let(:json) { MatrixDecorator.new(query_results).to_json(user_options: { base_url: 'http://example.org' }) }
104
114
  let(:parsed_json) { JSON.parse(json, symbolize_names: true) }
105
115
 
106
116
  it "includes the consumer details" do
@@ -121,13 +131,14 @@ module PactBroker
121
131
 
122
132
  it "includes a summary" do
123
133
  expect(parsed_json[:summary][:deployable]).to eq true
124
- expect(parsed_json[:summary][:reason]).to match /All verification results are published/
134
+ expect(parsed_json[:summary][:reason]).to eq "foo\nbar"
135
+ expect(parsed_json[:summary][:success]).to eq 1
125
136
  end
126
137
 
127
138
  context "when the pact has not been verified" do
128
139
  before do
129
- allow(line_2).to receive(:success).and_return(nil)
130
- allow(line_2).to receive(:verification_executed_at).and_return(nil)
140
+ allow(row_2).to receive(:success).and_return(nil)
141
+ allow(row_2).to receive(:verification_executed_at).and_return(nil)
131
142
  end
132
143
 
133
144
  let(:verification_hash) { nil }
@@ -140,42 +151,6 @@ module PactBroker
140
151
  expect(parsed_json[:matrix][1][:verificationResult]).to eq verification_hash
141
152
  end
142
153
  end
143
-
144
- context "when one or more successes are nil" do
145
- let(:line_1_success) { nil }
146
-
147
- it "has a deployable flag of nil" do
148
- expect(parsed_json[:summary][:deployable]).to be nil
149
- end
150
-
151
- it "has an explanation" do
152
- expect(parsed_json[:summary][:reason]).to match /Missing/
153
- end
154
- end
155
-
156
- context "when one or more successes are false" do
157
- let(:line_1_success) { false }
158
-
159
- it "has a deployable flag of false" do
160
- expect(parsed_json[:summary][:deployable]).to be false
161
- end
162
-
163
- it "has an explanation" do
164
- expect(parsed_json[:summary][:reason]).to match /have failed/
165
- end
166
- end
167
-
168
- context "when there are no results" do
169
- let(:lines) { [] }
170
-
171
- it "has a deployable flag of false" do
172
- expect(parsed_json[:summary][:deployable]).to be nil
173
- end
174
-
175
- it "has an explanation" do
176
- expect(parsed_json[:summary][:reason]).to match /No results/
177
- end
178
- end
179
154
  end
180
155
  end
181
156
  end
@@ -13,7 +13,8 @@ module PactBroker
13
13
  {
14
14
  base_url: 'http://example.org',
15
15
  resource_url: 'http://example.org/provider-pacts',
16
- title: 'title'
16
+ title: 'title',
17
+ provider_name: 'foo'
17
18
  }
18
19
  end
19
20
 
@@ -30,9 +31,9 @@ module PactBroker
30
31
  :href=> "http://example.org/provider-pacts",
31
32
  :title => "title"
32
33
  },
33
- :provider => {
34
- :href => "http://example.org/pacticipants/",
35
- :title => nil
34
+ :"pb:provider" => {
35
+ :href => "http://example.org/pacticipants/foo",
36
+ :name => "foo"
36
37
  },
37
38
  :"pb:pacts" =>[{
38
39
  :href => "pact_url",
@@ -0,0 +1,98 @@
1
+ require 'pact_broker/matrix/deployment_status_summary'
2
+ require 'pact_broker/matrix/row'
3
+ require 'pact_broker/matrix/query_results'
4
+ require 'pact_broker/matrix/integration'
5
+
6
+ module PactBroker
7
+ module Matrix
8
+ describe DeploymentStatusSummary do
9
+ describe ".call" do
10
+
11
+ let(:rows) { [row_1, row_2] }
12
+ let(:row_1) do
13
+ double(Row,
14
+ consumer_name: "Foo",
15
+ consumer_id: 1,
16
+ provider_name: "Bar",
17
+ provider_id: 2,
18
+ success: row_1_success
19
+ )
20
+ end
21
+
22
+ let(:row_2) do
23
+ double(Row,
24
+ consumer_name: "Foo",
25
+ consumer_id: 1,
26
+ provider_name: "Baz",
27
+ provider_id: 3,
28
+ success: true
29
+ )
30
+ end
31
+
32
+ let(:row_1_success) { true }
33
+
34
+ let(:integrations) do
35
+ [
36
+ Integration.new(1, "Foo", 2, "Bar"),
37
+ Integration.new(1, "Foo", 3, "Baz")
38
+ ]
39
+ end
40
+
41
+ let(:resolved_selectors) do
42
+ [
43
+ {
44
+ pacticipant_id: 1, pacticipant_version_number: "ddec8101dabf4edf9125a69f9a161f0f294af43c"
45
+ },
46
+ {
47
+ pacticipant_id: 2, pacticipant_version_number: "14131c5da3abf323ccf410b1b619edac76231243"
48
+ },
49
+ {
50
+ pacticipant_id: 3, pacticipant_version_number: "4ee06460f10e8207ad904fa9fa6c4842e462ab59"
51
+ }
52
+ ]
53
+ end
54
+
55
+
56
+ subject { DeploymentStatusSummary.new(rows, resolved_selectors, integrations) }
57
+
58
+ context "when there is a row for all integrations" do
59
+ its(:deployable?) { is_expected.to be true }
60
+ its(:reasons) { is_expected.to eq ["All verification results are published and successful"] }
61
+ its(:counts) { is_expected.to eq success: 2, failed: 0, unknown: 0 }
62
+ end
63
+
64
+ context "when there are no rows" do
65
+ let(:rows) { [] }
66
+
67
+ its(:deployable?) { is_expected.to be nil }
68
+ its(:reasons) { is_expected.to eq ["No results matched the given query"] }
69
+ its(:counts) { is_expected.to eq success: 0, failed: 0, unknown: 2 }
70
+ end
71
+
72
+ context "when one or more of the success flags are nil" do
73
+ let(:row_1_success) { nil }
74
+
75
+ its(:deployable?) { is_expected.to be nil }
76
+ its(:reasons) { is_expected.to eq ["Missing one or more verification results"] }
77
+ its(:counts) { is_expected.to eq success: 1, failed: 0, unknown: 1 }
78
+ end
79
+
80
+ context "when one or more of the success flags are false" do
81
+ let(:row_1_success) { false }
82
+
83
+ its(:deployable?) { is_expected.to be false }
84
+ its(:reasons) { is_expected.to eq ["One or more verifications have failed"] }
85
+ its(:counts) { is_expected.to eq success: 1, failed: 1, unknown: 0 }
86
+ end
87
+
88
+ context "when there is a relationship missing" do
89
+ let(:rows) { [row_1] }
90
+
91
+ its(:deployable?) { is_expected.to be nil }
92
+ its(:reasons) { is_expected.to eq ["There is no verified pact between Foo (ddec8101dabf4edf9125a69f9a161f0f294af43c) and Baz (4ee06460f10e8207ad904fa9fa6c4842e462ab59)"] }
93
+ its(:counts) { is_expected.to eq success: 1, failed: 0, unknown: 1 }
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
@@ -82,6 +82,14 @@ module PactBroker
82
82
  end
83
83
  end
84
84
 
85
+ context "when global latest is true" do
86
+ let(:query) { "q[][pacticipant]=Foo&latest=true" }
87
+
88
+ it "returns options with latest true" do
89
+ expect(subject.last).to eq latest: true
90
+ end
91
+ end
92
+
85
93
  context "when latest is not true" do
86
94
  let(:query) { "q[][pacticipant]=Foo&q[][latest]=false" }
87
95
 
@@ -0,0 +1,51 @@
1
+ require 'pact_broker/matrix/repository'
2
+
3
+ module PactBroker
4
+ module Matrix
5
+ describe Repository do
6
+ let(:td) { TestDataBuilder.new}
7
+
8
+ describe "find_integrations" do
9
+ before do
10
+ td.create_pact_with_hierarchy("foo", "1", "bar")
11
+ .create_provider("baz")
12
+ .create_pact
13
+ .use_consumer("baz")
14
+ .create_consumer_version("3")
15
+ .create_provider("wiffle")
16
+ .create_pact
17
+ end
18
+
19
+ subject { Repository.new.find_integrations(["foo"]).sort }
20
+
21
+ context "with only one pacticipant name" do
22
+ it "returns all the integrations that the pacticipant with the given name has" do
23
+ expect(subject.first.consumer_name).to eq "foo"
24
+ expect(subject.first.provider_name).to eq "bar"
25
+ expect(subject.last.consumer_name).to eq "foo"
26
+ expect(subject.last.provider_name).to eq "baz"
27
+ expect(subject.size).to eq 2
28
+ end
29
+ end
30
+
31
+ context "with the names of two pacticipants that are integrated" do
32
+ subject { Repository.new.find_integrations(["foo", "bar"]).sort }
33
+
34
+ it "returns only that integration" do
35
+ expect(subject.first.consumer_name).to eq "foo"
36
+ expect(subject.first.provider_name).to eq "bar"
37
+ expect(subject.size).to eq 1
38
+ end
39
+ end
40
+
41
+ context "with the names of two pacticipants that aren't integrated" do
42
+ subject { Repository.new.find_integrations(["foo", "wiffle"]).sort }
43
+
44
+ it "returns an empty array" do
45
+ expect(subject).to eq []
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -998,6 +998,30 @@ module PactBroker
998
998
  end
999
999
  end
1000
1000
  end
1001
+
1002
+ describe "find pact_broker-client issue 33" do
1003
+ before do
1004
+ td
1005
+ .create_consumer("foo")
1006
+ .create_provider("bar")
1007
+ .create_consumer_version("1.0.0")
1008
+ .create_pact
1009
+ .create_verification(provider_version: "10.0.0", tag_names: ["prod"])
1010
+ .create_provider("baz")
1011
+ .create_consumer_version("2.0.0")
1012
+ .create_pact
1013
+ .create_verification(provider_version: "20.0.0", tag_names: ["prod"])
1014
+ end
1015
+
1016
+ let(:selectors) { [{ pacticipant_name: "foo", pacticipant_version_number: "1.0.0" }] }
1017
+ let(:options) { {latestby: "cvp", latest: true, tag: "prod"} }
1018
+
1019
+ subject { shorten_rows(Repository.new.find(selectors, options)) }
1020
+
1021
+ it "only returns a row for the foo pact version that has been verified by the current production version of bar" do
1022
+ expect(subject).to eq ["foo1.0.0 bar10.0.0 n1"]
1023
+ end
1024
+ end
1001
1025
  end
1002
1026
  end
1003
1027
  end
@@ -5,6 +5,32 @@ module PactBroker
5
5
  describe Service do
6
6
  let(:td) { TestDataBuilder.new }
7
7
 
8
+ describe "find integration test" do
9
+ let(:selectors) do
10
+ [ { pacticipant_name: "foo" } ]
11
+ end
12
+
13
+ let(:options) do
14
+ { latest: true, tag: "prod" }
15
+ end
16
+
17
+ before do
18
+ td.create_pact_with_hierarchy("foo", "1", "bar")
19
+ .create_verification(provider_version: "2", tag_names: ["prod"])
20
+ end
21
+
22
+ subject { Service.find(selectors, options) }
23
+
24
+ it "returns a QueryResultsWithDeploymentStatusSummary" do
25
+ expect(subject.rows).to be_a(Array)
26
+ expect(subject.selectors).to be selectors
27
+ expect(subject.options).to be options
28
+ expect(subject.resolved_selectors).to be_a(Array)
29
+ expect(subject.resolved_selectors.count).to eq 2
30
+ expect(subject.deployment_status_summary).to be_a(DeploymentStatusSummary)
31
+ end
32
+ end
33
+
8
34
  describe "validate_selectors" do
9
35
 
10
36
  subject { Service.validate_selectors(selectors) }
@@ -275,6 +275,26 @@ module PactBroker
275
275
  end
276
276
  end
277
277
  end
278
+
279
+ describe "delete_by_provider_version_id" do
280
+ let!(:provider_version) do
281
+ TestDataBuilder.new
282
+ .create_consumer
283
+ .create_provider
284
+ .create_consumer_version
285
+ .create_pact
286
+ .create_verification(provider_version: "1.0.0")
287
+ .create_verification(provider_version: "2.0.0", number: 2)
288
+ .create_verification(provider_version: "2.0.0", number: 3)
289
+ .and_return(:provider_version)
290
+ end
291
+
292
+ subject { Repository.new.delete_by_provider_version_id(provider_version.id) }
293
+
294
+ it "deletes the verifications associated with the given version id" do
295
+ expect { subject }.to change { PactBroker::Domain::Verification.count }.by(-2)
296
+ end
297
+ end
278
298
  end
279
299
  end
280
300
  end
@@ -5,13 +5,15 @@ module PactBroker
5
5
  module Versions
6
6
  describe Service do
7
7
  describe ".delete" do
8
+ let(:td) { TestDataBuilder.new }
8
9
  let!(:version) do
9
- TestDataBuilder.new
10
+ td
10
11
  .create_consumer
11
12
  .create_provider
12
13
  .create_consumer_version("1.2.3")
13
14
  .create_consumer_version_tag("prod")
14
15
  .create_pact
16
+ .create_verification(provider_version: "1.0.0")
15
17
  .and_return(:consumer_version)
16
18
  end
17
19
 
@@ -28,6 +30,12 @@ module PactBroker
28
30
  it "deletes the version" do
29
31
  expect{ subject }.to change { PactBroker::Domain::Version.count }.by(-1)
30
32
  end
33
+
34
+ context "when deleting a provider version" do
35
+ it "deletes associated verifications" do
36
+ expect { Service.delete(td.provider_version ) }. to change { PactBroker::Domain::Verification.count }.by(-1)
37
+ end
38
+ end
31
39
  end
32
40
  end
33
41
  end
@@ -34,6 +34,7 @@ class TestDataBuilder
34
34
  attr_reader :consumer
35
35
  attr_reader :provider
36
36
  attr_reader :consumer_version
37
+ attr_reader :provider_version
37
38
  attr_reader :pact
38
39
  attr_reader :verification
39
40
  attr_reader :webhook
@@ -320,10 +321,11 @@ class TestDataBuilder
320
321
  parameters.delete(:provider_version)
321
322
  verification = PactBroker::Domain::Verification.new(parameters)
322
323
  @verification = PactBroker::Verifications::Repository.new.create(verification, provider_version_number, @pact)
324
+ @provider_version = PactBroker::Domain::Version.where(pacticipant_id: @provider.id, number: provider_version_number).single_record
325
+
323
326
  if tag_names.any?
324
- provider_version = PactBroker::Domain::Version.where(pacticipant_id: @provider.id, number: provider_version_number).single_record
325
327
  tag_names.each do | tag_name |
326
- PactBroker::Domain::Tag.create(name: tag_name, version: provider_version)
328
+ PactBroker::Domain::Tag.create(name: tag_name, version: @provider_version)
327
329
  end
328
330
  end
329
331
  refresh_matrix
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pact_broker
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.23.3
4
+ version: 2.23.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bethany Skurrie
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2018-06-26 00:00:00.000000000 Z
13
+ date: 2018-07-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: httparty
@@ -824,8 +824,12 @@ files:
824
824
  - lib/pact_broker/locale/en.yml
825
825
  - lib/pact_broker/logging.rb
826
826
  - lib/pact_broker/matrix/aggregated_row.rb
827
+ - lib/pact_broker/matrix/deployment_status_summary.rb
827
828
  - lib/pact_broker/matrix/head_row.rb
829
+ - lib/pact_broker/matrix/integration.rb
828
830
  - lib/pact_broker/matrix/parse_query.rb
831
+ - lib/pact_broker/matrix/query_results.rb
832
+ - lib/pact_broker/matrix/query_results_with_deployment_status_summary.rb
829
833
  - lib/pact_broker/matrix/repository.rb
830
834
  - lib/pact_broker/matrix/row.rb
831
835
  - lib/pact_broker/matrix/service.rb
@@ -1130,8 +1134,10 @@ files:
1130
1134
  - spec/lib/pact_broker/labels/repository_spec.rb
1131
1135
  - spec/lib/pact_broker/labels/service_spec.rb
1132
1136
  - spec/lib/pact_broker/matrix/aggregated_row_spec.rb
1137
+ - spec/lib/pact_broker/matrix/deployment_status_summary_spec.rb
1133
1138
  - spec/lib/pact_broker/matrix/head_row_spec.rb
1134
1139
  - spec/lib/pact_broker/matrix/parse_query_spec.rb
1140
+ - spec/lib/pact_broker/matrix/repository_find_integrations_spec.rb
1135
1141
  - spec/lib/pact_broker/matrix/repository_spec.rb
1136
1142
  - spec/lib/pact_broker/matrix/row_spec.rb
1137
1143
  - spec/lib/pact_broker/matrix/service_spec.rb
@@ -1431,8 +1437,10 @@ test_files:
1431
1437
  - spec/lib/pact_broker/labels/repository_spec.rb
1432
1438
  - spec/lib/pact_broker/labels/service_spec.rb
1433
1439
  - spec/lib/pact_broker/matrix/aggregated_row_spec.rb
1440
+ - spec/lib/pact_broker/matrix/deployment_status_summary_spec.rb
1434
1441
  - spec/lib/pact_broker/matrix/head_row_spec.rb
1435
1442
  - spec/lib/pact_broker/matrix/parse_query_spec.rb
1443
+ - spec/lib/pact_broker/matrix/repository_find_integrations_spec.rb
1436
1444
  - spec/lib/pact_broker/matrix/repository_spec.rb
1437
1445
  - spec/lib/pact_broker/matrix/row_spec.rb
1438
1446
  - spec/lib/pact_broker/matrix/service_spec.rb