Skip to content

Commit

Permalink
fix(matrix): gracefully handle and log when version is unresolved
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Sep 7, 2018
1 parent ac60908 commit 82fe19f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
10 changes: 9 additions & 1 deletion lib/pact_broker/matrix/deployment_status_summary.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'pact_broker/logging'

module PactBroker
module Matrix
class DeploymentStatusSummary
Expand Down Expand Up @@ -82,7 +84,13 @@ def missing_reasons
end

def resolved_version_for(pacticipant_id)
resolved_selectors.find{ | s| s[:pacticipant_id] == pacticipant_id }[:pacticipant_version_number]
resolved_selector = resolved_selectors.find{ | s| s[:pacticipant_id] == pacticipant_id }
if resolved_selector
resolved_selector[:pacticipant_version_number]
else
PactBroker.logger.warn "Could not find the resolved version for pacticipant_id #{pacticipant_id} from integrations #{integrations.collect(&:to_s).join(", ")} in resolved selectors #{resolved_selectors.inspect}"
"unresolved version"
end
end
end
end
Expand Down
22 changes: 20 additions & 2 deletions spec/lib/pact_broker/matrix/deployment_status_summary_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ module PactBroker
module Matrix
describe DeploymentStatusSummary do
describe ".call" do

let(:rows) { [row_1, row_2] }
let(:row_1) do
double(Row,
Expand Down Expand Up @@ -52,7 +51,6 @@ module Matrix
]
end


subject { DeploymentStatusSummary.new(rows, resolved_selectors, integrations) }

context "when there is a row for all integrations" do
Expand Down Expand Up @@ -92,6 +90,26 @@ module Matrix
its(:reasons) { is_expected.to eq ["There is no verified pact between Foo (ddec8101dabf4edf9125a69f9a161f0f294af43c) and Baz (4ee06460f10e8207ad904fa9fa6c4842e462ab59)"] }
its(:counts) { is_expected.to eq success: 1, failed: 0, unknown: 1 }
end

context "when there is something unexpected about the data and the resolved selector cannot be found" do
let(:rows) { [row_1] }

let(:resolved_selectors) do
[
{
pacticipant_id: 3, pacticipant_version_number: "4ee06460f10e8207ad904fa9fa6c4842e462ab59"
}
]
end

its(:deployable?) { is_expected.to be nil }
its(:reasons) { is_expected.to eq ["There is no verified pact between Foo (unresolved version) and Baz (4ee06460f10e8207ad904fa9fa6c4842e462ab59)"] }

it "logs a warning" do
expect(PactBroker.logger).to receive(:warn).with(/Could not find the resolved version/)
subject.reasons
end
end
end
end
end
Expand Down

0 comments on commit 82fe19f

Please sign in to comment.