-
-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: correct the logic for determining the deployment status in the m…
…atrix resource When there are multiple integrations, and one integration returns a matching matrix row for the can-i-deploy query, while another other doesn't, the deployable status should not be true. Closes: pact-foundation/pact_broker-client#33
- Loading branch information
Showing
15 changed files
with
460 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,9 +22,7 @@ def to_csv | |
def pacts | ||
pact_service.find_latest_pacts | ||
end | ||
|
||
end | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
module PactBroker | ||
module Matrix | ||
class DeploymentStatusSummary | ||
attr_reader :rows, :resolved_selectors, :integrations | ||
|
||
def initialize(rows, resolved_selectors, integrations) | ||
@rows = rows | ||
@resolved_selectors = resolved_selectors | ||
@integrations = integrations | ||
end | ||
|
||
def counts | ||
{ | ||
success: rows.count{ |row| row.success }, | ||
failed: rows.count { |row| row.success == false }, | ||
unknown: integrations_without_a_row.count + rows.count { |row| row.success.nil? } | ||
} | ||
end | ||
|
||
def deployable? | ||
return nil if rows.empty? | ||
return nil if rows.any?{ |row| row.success.nil? } | ||
return nil if integrations_without_a_row.any? | ||
rows.all?{ |row| row.success } | ||
end | ||
|
||
def reasons | ||
@reasons ||= begin | ||
reasons = [] | ||
if rows.empty? | ||
reasons << "No results matched the given query" | ||
else | ||
reasons.concat(missing_reasons) | ||
reasons.concat(failure_messages) | ||
reasons.concat(unverified_messages) | ||
reasons.concat(success_messages) | ||
end | ||
reasons | ||
end | ||
end | ||
|
||
def unverified_messages | ||
if rows.any?{ |row| row.success.nil? } | ||
["Missing one or more verification results"] | ||
else | ||
[] | ||
end | ||
end | ||
|
||
def failure_messages | ||
if rows.any?{ |row| row.success == false } | ||
["One or more verifications have failed"] | ||
else | ||
[] | ||
end | ||
end | ||
|
||
def success_messages | ||
if rows.all?{ |row| row.success } && integrations_without_a_row.empty? | ||
["All verification results are published and successful"] | ||
else | ||
[] | ||
end | ||
end | ||
|
||
def integrations_without_a_row | ||
@integrations_without_a_row ||= begin | ||
integrations.select do | relationship | | ||
!rows.find do | row | | ||
row.consumer_id == relationship.consumer_id && row.provider_id == relationship.provider_id | ||
end | ||
end | ||
end | ||
end | ||
|
||
def missing_reasons | ||
integrations_without_a_row.collect do | missing_relationship| | ||
consumer_version_desc = "#{missing_relationship.consumer_name} (#{resolved_version_for(missing_relationship.consumer_id)})" | ||
provider_version_desc = "#{missing_relationship.provider_name} (#{resolved_version_for(missing_relationship.provider_id)})" | ||
"There is no verified pact between #{consumer_version_desc} and #{provider_version_desc}" | ||
end | ||
end | ||
|
||
def resolved_version_for(pacticipant_id) | ||
resolved_selectors.find{ | s| s[:pacticipant_id] == pacticipant_id }[:pacticipant_version_number] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# | ||
# Represents the integration relationship between a consumer and a provider | ||
# | ||
module PactBroker | ||
module Matrix | ||
class Integration | ||
|
||
attr_reader :consumer_name, :consumer_id, :provider_name, :provider_id | ||
|
||
def initialize consumer_id, consumer_name, provider_id, provider_name | ||
@consumer_id = consumer_id | ||
@consumer_name = consumer_name | ||
@provider_id = provider_id | ||
@provider_name = provider_name | ||
end | ||
|
||
def self.from_hash hash | ||
new( | ||
hash.fetch(:consumer_id), | ||
hash.fetch(:consumer_name), | ||
hash.fetch(:provider_id), | ||
hash.fetch(:provider_name) | ||
) | ||
end | ||
|
||
def == other | ||
consumer_id == other.consumer_id && provider_id == other.provider_id | ||
end | ||
|
||
def <=> other | ||
comparison = consumer_name <=> other.consumer_name | ||
return comparison if comparison != 0 | ||
provider_name <=> other.provider_name | ||
end | ||
|
||
def to_hash | ||
{ | ||
consumer_name: consumer_name, | ||
consumer_id: consumer_id, | ||
provider_name: provider_name, | ||
provider_id: provider_id, | ||
} | ||
end | ||
|
||
def pacticipant_names | ||
[consumer_name, provider_name] | ||
end | ||
|
||
def to_s | ||
"Relationship between #{consumer_name} (id=#{consumer_id}) and #{provider_name} (id=#{provider_id})" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module PactBroker | ||
module Matrix | ||
class QueryResults < Array | ||
attr_reader :selectors, :options, :resolved_selectors | ||
|
||
def initialize rows, selectors, options, resolved_selectors | ||
super(rows) | ||
@selectors = selectors | ||
@resolved_selectors = resolved_selectors | ||
@options = options | ||
end | ||
|
||
def rows | ||
to_a | ||
end | ||
end | ||
end | ||
end |
14 changes: 14 additions & 0 deletions
14
lib/pact_broker/matrix/query_results_with_deployment_status_summary.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require 'pact_broker/matrix/query_results' | ||
|
||
module PactBroker | ||
module Matrix | ||
class QueryResultsWithDeploymentStatusSummary < QueryResults | ||
attr_reader :deployment_status_summary | ||
|
||
def initialize rows, selectors, options, resolved_selectors, deployment_status_summary | ||
super(rows, selectors, options, resolved_selectors) | ||
@deployment_status_summary = deployment_status_summary | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.