Skip to content

Commit 8f64288

Browse files
committed
feat: raise explicit error if a matrix query is done for a version with a tag that does not exist
1 parent 5f6e3c1 commit 8f64288

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

lib/pact_broker/matrix/repository.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -144,21 +144,23 @@ def look_up_version_numbers(selectors, options)
144144
selectors.collect do | selector |
145145
if selector[:tag] && selector[:latest]
146146
version = version_repository.find_by_pacticipant_name_and_latest_tag(selector[:pacticipant_name], selector[:tag])
147-
raise Error.new("Could not find version with tag #{selector[:tag].inspect} for #{selector[:pacticipant_name]}") unless version
147+
raise Error.new("No version of #{selector[:pacticipant_name]} found with tag #{selector[:tag]}") unless version
148148
# validation in resource should ensure we always have a version
149149
{
150150
pacticipant_name: selector[:pacticipant_name],
151151
pacticipant_version_number: version.number
152152
}
153153
elsif selector[:latest]
154154
version = version_repository.find_latest_by_pacticpant_name(selector[:pacticipant_name])
155+
raise Error.new("No version of #{selector[:pacticipant_name]} found") unless version
155156
{
156157
pacticipant_name: selector[:pacticipant_name],
157158
pacticipant_version_number: version.number
158159
}
159160
elsif selector[:tag]
160161
# validation in resource should ensure we always have at least one version
161162
versions = version_repository.find_by_pacticipant_name_and_tag(selector[:pacticipant_name], selector[:tag])
163+
raise Error.new("No version of #{selector[:pacticipant_name]} found with tag #{selector[:tag]}") unless versions.any?
162164
versions.collect do | version |
163165
{
164166
pacticipant_name: selector[:pacticipant_name],

spec/lib/pact_broker/matrix/repository_spec.rb

+33
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,39 @@ def shorten_rows rows
964964
expect(subject.count).to eq 0
965965
end
966966
end
967+
968+
context "when there is no version for the specified tag" do
969+
before do
970+
TestDataBuilder.new
971+
.create_pact_with_hierarchy("D", "1", "E")
972+
end
973+
974+
subject { Repository.new.find(selectors) }
975+
976+
context "when the latest tag is specified" do
977+
let(:selectors) { [{ pacticipant_name: 'D', latest: true, tag: 'dev' } ] }
978+
979+
it "raises an error" do
980+
expect { subject }.to raise_error Error, /No version of D found/
981+
end
982+
end
983+
984+
context "when all tags are specified" do
985+
let(:selectors) { [{ pacticipant_name: 'D', tag: 'dev' } ] }
986+
987+
it "raises an error" do
988+
expect { subject }.to raise_error Error, /No version of D found/
989+
end
990+
end
991+
992+
context "when no tags are specified" do
993+
let(:selectors) { [{ pacticipant_name: 'E', latest: true } ] }
994+
995+
it "raises an error" do
996+
expect { subject }.to raise_error Error, /No version of E found/
997+
end
998+
end
999+
end
9671000
end
9681001
end
9691002
end

0 commit comments

Comments
 (0)