diff --git a/lib/pact_broker/matrix/deployment_status_summary.rb b/lib/pact_broker/matrix/deployment_status_summary.rb index 2b60c2aaa..3626932d6 100644 --- a/lib/pact_broker/matrix/deployment_status_summary.rb +++ b/lib/pact_broker/matrix/deployment_status_summary.rb @@ -1,3 +1,5 @@ +require 'pact_broker/logging' + module PactBroker module Matrix class DeploymentStatusSummary @@ -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 diff --git a/spec/lib/pact_broker/matrix/deployment_status_summary_spec.rb b/spec/lib/pact_broker/matrix/deployment_status_summary_spec.rb index dea249987..e3409169b 100644 --- a/spec/lib/pact_broker/matrix/deployment_status_summary_spec.rb +++ b/spec/lib/pact_broker/matrix/deployment_status_summary_spec.rb @@ -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, @@ -52,7 +51,6 @@ module Matrix ] end - subject { DeploymentStatusSummary.new(rows, resolved_selectors, integrations) } context "when there is a row for all integrations" do @@ -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