-
-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pacts for verification): allow a fallback tag to be specified
- Loading branch information
Showing
11 changed files
with
215 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
spec/lib/pact_broker/pacts/repository_find_for_verification_fallback_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
require 'pact_broker/pacts/repository' | ||
|
||
module PactBroker | ||
module Pacts | ||
describe Repository do | ||
let(:td) { TestDataBuilder.new } | ||
|
||
describe "#find_for_verification" do | ||
def find_by_consumer_version_number(consumer_version_number) | ||
subject.find{ |pact| pact.consumer_version_number == consumer_version_number } | ||
end | ||
|
||
def find_by_consumer_name_and_consumer_version_number(consumer_name, consumer_version_number) | ||
subject.find{ |pact| pact.consumer_name == consumer_name && pact.consumer_version_number == consumer_version_number } | ||
end | ||
|
||
subject { Repository.new.find_for_verification("Bar", consumer_version_selectors) } | ||
|
||
context "when there is a fallback tag specified" do | ||
before do | ||
td.create_pact_with_consumer_version_tag("Foo", "1", "master", "Bar") | ||
.create_pact_with_consumer_version_tag("Foo", "2", "feat-x", "Bar") | ||
end | ||
|
||
let(:tag) { "feat-x" } | ||
let(:fallback_tag) { "master" } | ||
let(:selector) { Selector.new(tag: tag, fallback_tag: fallback_tag, latest: true) } | ||
let(:consumer_version_selectors) { Selectors.new(selector) } | ||
|
||
context "when a pact exists for the main tag" do | ||
it "returns the pact with the main tag" do | ||
expect(find_by_consumer_version_number("2")).to_not be nil | ||
expect(find_by_consumer_version_number("2").selectors.first).to eq Selector.latest_for_tag(tag) | ||
end | ||
|
||
it "does not set the fallback_tag on the selector" do | ||
expect(find_by_consumer_version_number("2").selectors.first.fallback_tag).to be nil | ||
end | ||
end | ||
|
||
context "when a pact does not exist for the main tag and pact exists for the fallback tag" do | ||
let(:tag) { "no-existy" } | ||
|
||
it "returns the pact with the fallback tag" do | ||
expect(find_by_consumer_version_number("1")).to_not be nil | ||
end | ||
|
||
it "sets the fallback_tag on the selector" do | ||
expect(find_by_consumer_version_number("1").selectors.first.fallback_tag).to eq fallback_tag | ||
end | ||
|
||
it "sets the tag on the selector" do | ||
expect(find_by_consumer_version_number("1").selectors.first.tag).to eq tag | ||
end | ||
|
||
it "sets the latest flag on the selector" do | ||
expect(find_by_consumer_version_number("1").selectors.first.latest).to be true | ||
end | ||
end | ||
|
||
context "when a pact does not exist for either tag or fallback_tag" do | ||
let(:tag) { "no-existy" } | ||
let(:fallback_tag) { "also-no-existy" } | ||
|
||
it "returns an empty list" do | ||
expect(subject).to be_empty | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |