Skip to content

Commit

Permalink
feat: raise explicit error if a matrix query is done for a version wi…
Browse files Browse the repository at this point in the history
…th a tag that does not exist
  • Loading branch information
bethesque committed Jun 14, 2018
1 parent 5f6e3c1 commit 8f64288
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/pact_broker/matrix/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,21 +144,23 @@ def look_up_version_numbers(selectors, options)
selectors.collect do | selector |
if selector[:tag] && selector[:latest]
version = version_repository.find_by_pacticipant_name_and_latest_tag(selector[:pacticipant_name], selector[:tag])
raise Error.new("Could not find version with tag #{selector[:tag].inspect} for #{selector[:pacticipant_name]}") unless version
raise Error.new("No version of #{selector[:pacticipant_name]} found with tag #{selector[:tag]}") unless version
# validation in resource should ensure we always have a version
{
pacticipant_name: selector[:pacticipant_name],
pacticipant_version_number: version.number
}
elsif selector[:latest]
version = version_repository.find_latest_by_pacticpant_name(selector[:pacticipant_name])
raise Error.new("No version of #{selector[:pacticipant_name]} found") unless version
{
pacticipant_name: selector[:pacticipant_name],
pacticipant_version_number: version.number
}
elsif selector[:tag]
# validation in resource should ensure we always have at least one version
versions = version_repository.find_by_pacticipant_name_and_tag(selector[:pacticipant_name], selector[:tag])
raise Error.new("No version of #{selector[:pacticipant_name]} found with tag #{selector[:tag]}") unless versions.any?
versions.collect do | version |
{
pacticipant_name: selector[:pacticipant_name],
Expand Down
33 changes: 33 additions & 0 deletions spec/lib/pact_broker/matrix/repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,39 @@ def shorten_rows rows
expect(subject.count).to eq 0
end
end

context "when there is no version for the specified tag" do
before do
TestDataBuilder.new
.create_pact_with_hierarchy("D", "1", "E")
end

subject { Repository.new.find(selectors) }

context "when the latest tag is specified" do
let(:selectors) { [{ pacticipant_name: 'D', latest: true, tag: 'dev' } ] }

it "raises an error" do
expect { subject }.to raise_error Error, /No version of D found/
end
end

context "when all tags are specified" do
let(:selectors) { [{ pacticipant_name: 'D', tag: 'dev' } ] }

it "raises an error" do
expect { subject }.to raise_error Error, /No version of D found/
end
end

context "when no tags are specified" do
let(:selectors) { [{ pacticipant_name: 'E', latest: true } ] }

it "raises an error" do
expect { subject }.to raise_error Error, /No version of E found/
end
end
end
end
end
end
Expand Down

0 comments on commit 8f64288

Please sign in to comment.