Class: PactBroker::Pacts::VerifiablePactMessages

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/pact_broker/pacts/verifiable_pact_messages.rb

Constant Summary collapse

READ_MORE_PENDING =
"Read more at https://pact.io/pending"
READ_MORE_WIP =
"Read more at https://pact.io/wip"

Instance Method Summary collapse

Constructor Details

#initialize(verifiable_pact, pact_version_url) ⇒ VerifiablePactMessages

Returns a new instance of VerifiablePactMessages.



13
14
15
16
# File 'lib/pact_broker/pacts/verifiable_pact_messages.rb', line 13

def initialize(verifiable_pact, pact_version_url)
  @verifiable_pact = verifiable_pact
  @pact_version_url = pact_version_url
end

Instance Method Details

#inclusion_reasonObject



28
29
30
31
32
33
34
35
36
37
# File 'lib/pact_broker/pacts/verifiable_pact_messages.rb', line 28

def inclusion_reason
  version_text = head_consumer_tags.size == 1 || branches.size == 1 ? "version" : "versions"
  if wip?
    # WIP pacts will always have tags, because it is part of the definition of being a WIP pact
    "The pact at #{pact_version_url} is being verified because it is a 'work in progress' pact (ie. it is the pact for the latest #{version_text} of #{consumer_name} #{joined_head_consumer_tags_and_branches} and is still in pending state). #{READ_MORE_WIP}"
  else
    criteria_or_criterion = selectors.size > 1 ? "criteria" : "criterion"
    "The pact at #{pact_version_url} is being verified because it matches the following configured selection #{criteria_or_criterion}: #{selector_descriptions}#{same_content_note}"
  end
end

#pact_descriptionObject



18
19
20
21
22
23
24
25
26
# File 'lib/pact_broker/pacts/verifiable_pact_messages.rb', line 18

def pact_description
  position_descs = if head_consumer_tags.empty? && branches.empty?
    ["latest"]
  else
    head_consumer_tags.collect { |tag| "latest with tag #{tag}" } + branches.collect{ |branch| "latest from branch #{branch}" }
  end

  "Pact between #{consumer_name} and #{provider_name}, consumer version #{consumer_version_number}, #{position_descs.join(", ")}"
end

#pact_version_short_descriptionObject



69
70
71
# File 'lib/pact_broker/pacts/verifiable_pact_messages.rb', line 69

def pact_version_short_description
  short_selector_descriptions
end

#pending_reasonObject



39
40
41
42
43
44
45
# File 'lib/pact_broker/pacts/verifiable_pact_messages.rb', line 39

def pending_reason
  if pending?
    "This pact is in pending state for this version of #{provider_name} because a successful verification result for #{pending_provider_branch_or_tags_description("a")} has not yet been published. If this verification fails, it will not cause the overall build to fail. #{READ_MORE_PENDING}"
  else
    "This pact has previously been successfully verified by #{non_pending_provider_branch_or_tags_description}. If this verification fails, it will fail the build. #{READ_MORE_PENDING}"
  end
end

#verification_success_false_published_falseObject



59
60
61
62
63
# File 'lib/pact_broker/pacts/verifiable_pact_messages.rb', line 59

def verification_success_false_published_false
  if pending?
    "This pact is still in pending state for #{pending_provider_branch_or_tags_description} as a successful verification result #{with_these_tags}has not yet been published"
  end
end

#verification_success_false_published_trueObject



65
66
67
# File 'lib/pact_broker/pacts/verifiable_pact_messages.rb', line 65

def verification_success_false_published_true
  verification_success_false_published_false
end

#verification_success_true_published_falseObject



47
48
49
50
51
# File 'lib/pact_broker/pacts/verifiable_pact_messages.rb', line 47

def verification_success_true_published_false
  if pending?
    "This pact is still in pending state for #{pending_provider_branch_or_tags_description} as the successful verification results #{with_these_tags}have not yet been published."
  end
end

#verification_success_true_published_trueObject



53
54
55
56
57
# File 'lib/pact_broker/pacts/verifiable_pact_messages.rb', line 53

def verification_success_true_published_true
  if pending?
    "This pact is no longer in pending state for #{pending_provider_branch_or_tags_description}, as a successful verification result #{with_these_tags}has been published. If a verification for a version of #{provider_name} #{with_these_tags}fails in the future, it will fail the build. #{READ_MORE_PENDING}"
  end
end