Skip to content

Commit 59ec8c8

Browse files
committed
feat(pacts for verification): update the inclusion notice text to handle 'all pacts for tag'
1 parent 32bb3dd commit 59ec8c8

File tree

6 files changed

+66
-26
lines changed

6 files changed

+66
-26
lines changed

lib/pact_broker/pacts/repository.rb

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
require 'pact_broker/repositories/helpers'
1717
require 'pact_broker/pacts/selected_pact'
1818
require 'pact_broker/pacts/selector'
19+
require 'pact_broker/pacts/selectors'
1920

2021
module PactBroker
2122
module Pacts

lib/pact_broker/pacts/selector.rb

+24-2
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,44 @@ def self.latest_for_tag(tag)
1313
Selector.new(latest: true, tag: tag)
1414
end
1515

16-
def self.one_of_tag(tag)
16+
def self.all_for_tag(tag)
1717
Selector.new(tag: tag)
1818
end
1919

20+
def self.from_hash hash
21+
Selector.new(hash)
22+
end
23+
2024
def tag
2125
self[:tag]
2226
end
2327

2428
def overall_latest?
25-
!!(latest && !tag)
29+
!!(latest? && !tag)
2630
end
2731

2832
def latest_for_tag?
2933
!!(latest && tag)
3034
end
3135

36+
def <=> other
37+
if overall_latest? || other.overall_latest?
38+
if overall_latest? == other.overall_latest?
39+
0
40+
else
41+
overall_latest? ? -1 : 1
42+
end
43+
elsif latest_for_tag? || other.latest_for_tag?
44+
if latest_for_tag? == other.latest_for_tag?
45+
tag <=> other.tag
46+
else
47+
latest_for_tag? ? -1 : 1
48+
end
49+
else
50+
tag <=> other.tag
51+
end
52+
end
53+
3254
private
3355

3456
def latest?

lib/pact_broker/pacts/selectors.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def initialize selectors
88
end
99

1010
def self.create_for_all_of_each_tag(tag_names)
11-
Selectors.new(tag_names.collect{ | tag_name | Selector.one_of_tag(tag_name) })
11+
Selectors.new(tag_names.collect{ | tag_name | Selector.all_for_tag(tag_name) })
1212
end
1313

1414
def self.create_for_overall_latest_of_each_tag(tag_names)

lib/pact_broker/pacts/service.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ def find_for_verification(provider_name, provider_version_tags, consumer_version
136136
private
137137

138138
def exclude_specified_pacts(wip_pacts, specified_pacts)
139-
wip_pacts.select do | wip_pact |
140-
!specified_pacts.any? do | specified_pacts |
139+
wip_pacts.reject do | wip_pact |
140+
specified_pacts.any? do | specified_pacts |
141141
wip_pact.pact_version_sha == specified_pacts.pact_version_sha
142142
end
143143
end

lib/pact_broker/pacts/verifiable_pact_messages.rb

+25-10
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,14 @@ def inclusion_reason
2929
# WIP pacts will always have tags, because it is part of the definition of being a WIP pact
3030
"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 Foo tagged with #{joined_head_consumer_tags} and is still in pending state). #{READ_MORE_WIP}"
3131
else
32-
if selectors.overall_latest?
33-
"The pact at #{pact_version_url} is being verified because it is the latest pact between #{consumer_name} and #{provider_name}."
34-
else
35-
"The pact at #{pact_version_url} is being verified because it is the pact for the latest #{version_text} of Foo tagged with #{joined_head_consumer_tags}"
36-
end
32+
criteria_or_criterion = selectors.size > 1 ? "criteria" : "criterion"
33+
"The pact at #{pact_version_url} is being verified because it matches the following configured selection #{criteria_or_criterion}: #{selector_descriptions}#{same_content_note}"
3734
end
3835
end
3936

4037
def pending_reason
4138
if pending?
42-
"This pact is in pending state because it has not yet been successfully verified by #{pending_provider_tags_description}. If this verification fails, it will not cause the overall build to fail. #{READ_MORE_PENDING}"
39+
"This pact is in pending state for this version of #{provider_name} because a successful verification result for #{pending_provider_tags_description("a")} has not yet been published. If this verification fails, it will not cause the overall build to fail. #{READ_MORE_PENDING}"
4340
else
4441
"This pact has previously been successfully verified by #{non_pending_provider_tags_description}. If this verification fails, it will fail the build. #{READ_MORE_PENDING}"
4542
end
@@ -87,18 +84,18 @@ def joined_head_consumer_tags
8784
end
8885

8986
def same_content_note
90-
case head_consumer_tags.size
87+
case selectors.size
9188
when 1 then ""
9289
when 2 then " (both have the same content)"
9390
else " (all have the same content)"
9491
end
9592
end
9693

97-
def pending_provider_tags_description
94+
def pending_provider_tags_description(any_or_a = "any")
9895
case pending_provider_tags.size
9996
when 0 then provider_name
100-
when 1 then "any version of #{provider_name} with tag '#{pending_provider_tags.first}'"
101-
else "any versions of #{provider_name} with tag #{join(pending_provider_tags)}"
97+
when 1 then "#{any_or_a} version of #{provider_name} with tag '#{pending_provider_tags.first}'"
98+
else "#{any_or_a} versions of #{provider_name} with tag #{join(pending_provider_tags)}"
10299
end
103100
end
104101

@@ -122,6 +119,24 @@ def head_consumer_tags
122119
selectors.tag_names_for_selectors_for_latest_pacts
123120
end
124121

122+
def selector_descriptions
123+
selectors.sort.collect do | selector |
124+
selector_description(selector)
125+
end.join(", ")
126+
end
127+
128+
def selector_description selector
129+
if selector.overall_latest?
130+
"latest pact between a consumer and #{provider_name}"
131+
elsif selector.latest_for_tag?
132+
"latest pact for a consumer version tagged '#{selector.tag}'"
133+
elsif selector.tag
134+
"pacts for all consumer versions tagged '#{selector.tag}'"
135+
else
136+
selector.to_json
137+
end
138+
end
139+
125140
def selectors
126141
verifiable_pact.selectors
127142
end

spec/lib/pact_broker/pacts/verifiable_pact_messages_spec.rb

+13-11
Original file line numberDiff line numberDiff line change
@@ -29,29 +29,25 @@ module Pacts
2929
describe "#inclusion_reason" do
3030
context "when there are no head consumer tags" do
3131
let(:selectors) { Selectors.create_for_overall_latest }
32-
its(:inclusion_reason) { is_expected.to include "The pact at http://pact is being verified because it is the latest pact between Foo and Bar." }
32+
its(:inclusion_reason) { is_expected.to include "The pact at http://pact is being verified because it matches the following configured selection criterion: latest pact between a consumer and Bar" }
3333
end
3434

3535
context "when there is 1 head consumer tags" do
3636
let(:selectors) { Selectors.create_for_overall_latest_of_each_tag(%w[dev]) }
37-
its(:inclusion_reason) { is_expected.to include "The pact at http://pact is being verified because it is the pact for the latest version of Foo tagged with 'dev'" }
37+
its(:inclusion_reason) { is_expected.to include "The pact at http://pact is being verified because it matches the following configured selection criterion: latest pact for a consumer version tagged 'dev'" }
3838
its(:pact_description) { is_expected.to eq "Pact between Foo and Bar, consumer version 123, latest dev"}
3939
end
4040

4141
context "when there are 2 head consumer tags" do
4242
let(:selectors) { Selectors.create_for_overall_latest_of_each_tag(%w[dev prod]) }
43-
its(:inclusion_reason) { is_expected.to include "The pact at http://pact is being verified because it is the pact for the latest versions of Foo tagged with 'dev' and 'prod' (both have the same content)" }
43+
its(:inclusion_reason) { is_expected.to include "The pact at http://pact is being verified because it matches the following configured selection criteria: latest pact for a consumer version tagged 'dev', latest pact for a consumer version tagged 'prod' (both have the same content)" }
4444
end
4545

4646
context "when there are 3 head consumer tags" do
4747
let(:selectors) { Selectors.create_for_overall_latest_of_each_tag(%w[dev prod feat-x]) }
48-
its(:inclusion_reason) { is_expected.to include "The pact at http://pact is being verified because it is the pact for the latest versions of Foo tagged with 'dev', 'prod' and 'feat-x' (all have the same content)" }
48+
its(:inclusion_reason) { is_expected.to include " (all have the same content)" }
4949
end
5050

51-
context "when there are 4 head consumer tags" do
52-
let(:selectors) { Selectors.create_for_overall_latest_of_each_tag(%w[dev prod feat-x feat-y]) }
53-
its(:inclusion_reason) { is_expected.to include "'dev', 'prod', 'feat-x' and 'feat-y'" }
54-
end
5551

5652
context "when the pact is a WIP pact" do
5753
let(:selectors) { Selectors.create_for_overall_latest_of_each_tag(%w[feat-x]) }
@@ -61,6 +57,12 @@ module Pacts
6157

6258
its(:inclusion_reason) { is_expected.to include "The pact at http://pact is being verified because it is a 'work in progress' pact (ie. it is the pact for the latest version of Foo tagged with 'feat-x' and is still in pending state)."}
6359
end
60+
61+
context "when the pact is one of all versions for a tag" do
62+
let(:selectors) { Selectors.create_for_all_of_each_tag(%w[prod]) }
63+
64+
its(:inclusion_reason) { is_expected.to include "The pact at http://pact is being verified because it matches the following configured selection criterion: pacts for all consumer versions tagged 'prod'"}
65+
end
6466
end
6567

6668
describe "#pending_reason" do
@@ -81,20 +83,20 @@ module Pacts
8183

8284
context "when there are no pending_provider_tags" do
8385
context "when there are no non_pending_provider_tags" do
84-
its(:pending_reason) { is_expected.to include "This pact is in pending state because it has not yet been successfully verified by Bar. If this verification fails, it will not cause the overall build to fail." }
86+
its(:pending_reason) { is_expected.to include "This pact is in pending state for this version of Bar because a successful verification result for Bar has not yet been published. If this verification fails, it will not cause the overall build to fail." }
8587
end
8688
end
8789

8890
context "when there is 1 pending_provider_tag" do
8991
let(:pending_provider_tags) { %w[dev] }
9092

91-
its(:pending_reason) { is_expected.to include "This pact is in pending state because it has not yet been successfully verified by any version of Bar with tag 'dev'. If this verification fails, it will not cause the overall build to fail." }
93+
its(:pending_reason) { is_expected.to include "This pact is in pending state for this version of Bar because a successful verification result for a version of Bar with tag 'dev' has not yet been published. If this verification fails, it will not cause the overall build to fail." }
9294
end
9395

9496
context "when there are 2 pending_provider_tags" do
9597
let(:pending_provider_tags) { %w[dev feat-x] }
9698

97-
its(:pending_reason) { is_expected.to include "This pact is in pending state because it has not yet been successfully verified by any versions of Bar with tag 'dev' and 'feat-x'." }
99+
its(:pending_reason) { is_expected.to include "This pact is in pending state for this version of Bar because a successful verification result for a versions of Bar with tag 'dev' and 'feat-x' has not yet been published. If this verification fails, it will not cause the overall build to fail." }
98100
end
99101

100102
context "when there are 3 pending_provider_tags" do

0 commit comments

Comments
 (0)