Skip to content

Commit 82fe19f

Browse files
committed
fix(matrix): gracefully handle and log when version is unresolved
For: pact-foundation#232
1 parent ac60908 commit 82fe19f

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

lib/pact_broker/matrix/deployment_status_summary.rb

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'pact_broker/logging'
2+
13
module PactBroker
24
module Matrix
35
class DeploymentStatusSummary
@@ -82,7 +84,13 @@ def missing_reasons
8284
end
8385

8486
def resolved_version_for(pacticipant_id)
85-
resolved_selectors.find{ | s| s[:pacticipant_id] == pacticipant_id }[:pacticipant_version_number]
87+
resolved_selector = resolved_selectors.find{ | s| s[:pacticipant_id] == pacticipant_id }
88+
if resolved_selector
89+
resolved_selector[:pacticipant_version_number]
90+
else
91+
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}"
92+
"unresolved version"
93+
end
8694
end
8795
end
8896
end

spec/lib/pact_broker/matrix/deployment_status_summary_spec.rb

+20-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ module PactBroker
77
module Matrix
88
describe DeploymentStatusSummary do
99
describe ".call" do
10-
1110
let(:rows) { [row_1, row_2] }
1211
let(:row_1) do
1312
double(Row,
@@ -52,7 +51,6 @@ module Matrix
5251
]
5352
end
5453

55-
5654
subject { DeploymentStatusSummary.new(rows, resolved_selectors, integrations) }
5755

5856
context "when there is a row for all integrations" do
@@ -92,6 +90,26 @@ module Matrix
9290
its(:reasons) { is_expected.to eq ["There is no verified pact between Foo (ddec8101dabf4edf9125a69f9a161f0f294af43c) and Baz (4ee06460f10e8207ad904fa9fa6c4842e462ab59)"] }
9391
its(:counts) { is_expected.to eq success: 1, failed: 0, unknown: 1 }
9492
end
93+
94+
context "when there is something unexpected about the data and the resolved selector cannot be found" do
95+
let(:rows) { [row_1] }
96+
97+
let(:resolved_selectors) do
98+
[
99+
{
100+
pacticipant_id: 3, pacticipant_version_number: "4ee06460f10e8207ad904fa9fa6c4842e462ab59"
101+
}
102+
]
103+
end
104+
105+
its(:deployable?) { is_expected.to be nil }
106+
its(:reasons) { is_expected.to eq ["There is no verified pact between Foo (unresolved version) and Baz (4ee06460f10e8207ad904fa9fa6c4842e462ab59)"] }
107+
108+
it "logs a warning" do
109+
expect(PactBroker.logger).to receive(:warn).with(/Could not find the resolved version/)
110+
subject.reasons
111+
end
112+
end
95113
end
96114
end
97115
end

0 commit comments

Comments
 (0)