-
-
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): update validation for consumer version …
…selectors for the fields environment, currentlyDeployed and branch
- Loading branch information
Showing
5 changed files
with
286 additions
and
12 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
73 changes: 73 additions & 0 deletions
73
spec/lib/pact_broker/api/contracts/verifiable_pacts_json_query_schema_combinations_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/api/contracts/verifiable_pacts_json_query_schema' | ||
|
||
module PactBroker | ||
module Api | ||
module Contracts | ||
describe VerifiablePactsJSONQuerySchema do | ||
ALL_PROPERTIES = { | ||
tag: "tag", | ||
branch: "branch", | ||
latest: true, | ||
fallbackTag: "fallbackTag", | ||
fallbackBranch: "fallbackBranch", | ||
environment: "environment", | ||
currentlyDeployed: true, | ||
consumer: "consumer" | ||
} | ||
|
||
VALID_KEY_COMBINATIONS = [ | ||
[:tag], | ||
[:tag, :latest], | ||
[:tag, :latest, :fallbackTag], | ||
[:branch], | ||
[:branch, :latest], | ||
[:branch, :latest, :fallbackBranch], | ||
[:branch, :fallbackBranch], | ||
[:environment], | ||
[:environment, :currentlyDeployed], | ||
[:currentlyDeployed], | ||
] | ||
|
||
VALID_KEY_COMBINATIONS.each do | valid_key_combination | | ||
selector = ALL_PROPERTIES.slice(*valid_key_combination) | ||
|
||
describe "with #{selector}" do | ||
it "is valid" do | ||
params = { consumerVersionSelectors: [selector] } | ||
expect(VerifiablePactsJSONQuerySchema.(params)).to be_empty | ||
end | ||
|
||
extra_keys = ALL_PROPERTIES.keys - valid_key_combination - [:consumer] | ||
extra_keys.each do | extra_key | | ||
selector_with_extra_key = selector.merge(extra_key => ALL_PROPERTIES[extra_key]) | ||
expect_to_be_valid = !!VALID_KEY_COMBINATIONS.find{ | valid_key_combination | valid_key_combination.sort == selector_with_extra_key.keys.sort } | ||
params = { consumerVersionSelectors: [selector_with_extra_key] } | ||
|
||
describe "with #{selector_with_extra_key}" do | ||
if expect_to_be_valid | ||
it "is valid" do | ||
expect(VerifiablePactsJSONQuerySchema.(params)).to be_empty | ||
end | ||
else | ||
it "is not valid" do | ||
expect(VerifiablePactsJSONQuerySchema.(params)).to_not be_empty | ||
end | ||
end | ||
end | ||
|
||
selector_with_consumer = selector.merge(consumer: ALL_PROPERTIES[:consumer]) | ||
|
||
describe "with #{selector_with_consumer}" do | ||
it "is valid" do | ||
params = { consumerVersionSelectors: [selector_with_consumer] } | ||
|
||
expect(VerifiablePactsJSONQuerySchema.(params).empty?).to be true | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
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