Skip to content

Commit

Permalink
feat(matrix): add support for selectors specified by branch and envir…
Browse files Browse the repository at this point in the history
…onment name when reporting that a version does not exist
  • Loading branch information
bethesque committed May 17, 2022
1 parent 3eb5581 commit 07ff804
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 15 deletions.
16 changes: 1 addition & 15 deletions lib/pact_broker/api/decorators/reason_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def reason_text
when PactBroker::Matrix::PactNotVerifiedByRequiredProviderVersion
"There is no verified pact between #{reason.consumer_selector.description} and #{reason.provider_selector.description}"
when PactBroker::Matrix::SpecifiedVersionDoesNotExist
version_does_not_exist_description(reason.selector)
reason.selector.version_does_not_exist_description
when PactBroker::Matrix::VerificationFailed
"The verification for the pact between #{reason.consumer_selector.description} and #{reason.provider_selector.description} failed"
when PactBroker::Matrix::NoDependenciesMissing
Expand All @@ -53,20 +53,6 @@ def reason_text
end
end

def version_does_not_exist_description selector
if selector.version_does_not_exist?
if selector.tag
"No version with tag #{selector.tag} exists for #{selector.pacticipant_name}"
elsif selector.pacticipant_version_number
"No pacts or verifications have been published for version #{selector.pacticipant_version_number} of #{selector.pacticipant_name}"
else
"No pacts or verifications have been published for #{selector.pacticipant_name}"
end
else
""
end
end

# TODO move this somewhere else
def interaction_description(interaction)
if interaction["providerState"] && interaction["providerState"] != ""
Expand Down
19 changes: 19 additions & 0 deletions lib/pact_broker/matrix/resolved_selector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def tag
self[:tag]
end

# @return [String] the name of the branch
def branch
self[:branch]
end
Expand Down Expand Up @@ -208,6 +209,24 @@ def description
end
end
# rubocop: enable Metrics/CyclomaticComplexity

def version_does_not_exist_description
if version_does_not_exist?
if tag
"No version with tag #{tag} exists for #{pacticipant_name}"
elsif branch
"No version of #{pacticipant_name} from branch #{branch} exists"
elsif environment_name
"No version of #{pacticipant_name} is currently recorded as deployed or released in environment #{environment_name}"
elsif pacticipant_version_number
"No pacts or verifications have been published for version #{pacticipant_version_number} of #{pacticipant_name}"
else
"No pacts or verifications have been published for #{pacticipant_name}"
end
else
""
end
end
end
end
end
8 changes: 8 additions & 0 deletions spec/lib/pact_broker/api/decorators/reason_decorator_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require "pact_broker/api/decorators/reason_decorator"
require "pact_broker/matrix/reason"
require "pact_broker/matrix/resolved_selector"

module PactBroker
module Api
Expand Down Expand Up @@ -88,6 +89,13 @@ module Decorators

its(:to_s) { is_expected.to start_with "WARN: It is recommended to specify the version number" }
end

context "when the reason is PactBroker::Matrix::SpecifiedVersionDoesNotExist" do
let(:reason) { PactBroker::Matrix::SpecifiedVersionDoesNotExist.new(selector) }
let(:selector) { instance_double("PactBroker::Matrix::ResolvedSelector", version_does_not_exist_description: "version_does_not_exist_description") }

its(:to_s) { is_expected.to eq "version_does_not_exist_description" }
end
end
end
end
Expand Down
57 changes: 57 additions & 0 deletions spec/lib/pact_broker/matrix/resolved_selector_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
require "pact_broker/matrix/resolved_selector"

module PactBroker
module Matrix
describe ResolvedSelector do
describe "#version_does_not_exist_description" do
let(:subject) do
PactBroker::Matrix::ResolvedSelector.for_pacticipant_and_non_existing_version(pacticipant, original_selector, :specified, false)
end

let(:original_selector) do
{
pacticipant_name: pacticipant_name,
tag: tag,
branch: branch,
environment_name: environment_name,
pacticipant_version_number: pacticipant_version_number,
}
end

let(:pacticipant) { double("pacticipant", name: pacticipant_name, id: 1)}

let(:pacticipant_name) { "Foo" }
let(:tag) { nil }
let(:branch) { nil }
let(:environment_name) { nil }
let(:pacticipant_version_number) { nil }

its(:version_does_not_exist_description) { is_expected.to eq "No pacts or verifications have been published for Foo" }

context "when it was specified by tag" do
let(:tag) { "dev" }

its(:version_does_not_exist_description) { is_expected.to eq "No version with tag dev exists for Foo" }
end

context "when it was specified by branch" do
let(:branch) { "main" }

its(:version_does_not_exist_description) { is_expected.to eq "No version of Foo from branch main exists" }
end

context "when it was specified by environment" do
let(:environment_name) { "test" }

its(:version_does_not_exist_description) { is_expected.to eq "No version of Foo is currently recorded as deployed or released in environment test" }
end

context "when it was specified by verison number" do
let(:pacticipant_version_number) { "1" }

its(:version_does_not_exist_description) { is_expected.to eq "No pacts or verifications have been published for version 1 of Foo" }
end
end
end
end
end

0 comments on commit 07ff804

Please sign in to comment.