Skip to content

Commit 87c3e9e

Browse files
committed
chore(test): support pact-broker-cli client
- update pact verification test to fetch from pact broker - update pact verifications to push branch to pickup new pact-broker-cli tests - create provider states for pact-broker-cli
1 parent 3753c2b commit 87c3e9e

File tree

5 files changed

+106
-16
lines changed

5 files changed

+106
-16
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,10 @@ jobs:
108108
with:
109109
bundler-cache: true
110110
- name: Verify pacts
111-
run: "GIT_SHA=${GITHUB_SHA} GIT_BRANCH=${GITHUB_REF##*/} bundle exec rake pact:verify"
111+
run: "GIT_SHA=${GITHUB_SHA} bundle exec rake pact:verify"
112112
env:
113-
PACTFLOW_PACT_FOUNDATION_TOKEN: ${{ secrets.PACTFLOW_PACT_FOUNDATION_TOKEN }}
113+
PACT_BROKER_TOKEN: ${{ secrets.PACTFLOW_PACT_FOUNDATION_TOKEN }}
114+
PACT_BROKER_BASE_URL: https://pact-foundation.pactflow.io
114115

115116
pact-v2-verify:
116117
runs-on: "ubuntu-latest"

spec/service_consumers/hal_relation_proxy_app.rb

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,36 +53,44 @@ class HalRelationProxyApp
5353
"latestby=cvpv&q%5B%5D%5Bpacticipant%5D=Foo&q%5B%5D%5Bpacticipant%5D=Bar&q%5B%5D%5Bversion%5D=1.2.3&q%5B%5D%5Bversion%5D=4.5.6" =>
5454
"q%5B%5D%5Bpacticipant%5D=Foo&q%5B%5D%5Bversion%5D=1.2.3&q%5B%5D%5Bpacticipant%5D=Bar&q%5B%5D%5Bversion%5D=4.5.6&latestby=cvpv",
5555
# pact-ruby-v2 pact (as v2) verified by pact-ruby-v1
56-
"latestby=cvpv&q[][pacticipant]=Foo&q[][pacticipant]=Bar&q[][version]=1%2e2%2e3&q[][version]=4%2e5%2e6" =>
57-
"q%5B%5D%5Bpacticipant%5D=Foo&q%5B%5D%5Bversion%5D=1.2.3&q%5B%5D%5Bpacticipant%5D=Bar&q%5B%5D%5Bversion%5D=4.5.6&latestby=cvpv",
56+
# "latestby=cvpv&q[][pacticipant]=Foo&q[][pacticipant]=Bar&q[][version]=1%2e2%2e3&q[][version]=4%2e5%2e6" =>
57+
# "q%5B%5D%5Bpacticipant%5D=Foo&q%5B%5D%5Bversion%5D=1.2.3&q%5B%5D%5Bpacticipant%5D=Bar&q%5B%5D%5Bversion%5D=4.5.6&latestby=cvpv",
5858

5959
# pact-ruby-v2 pact (as v2) verified by pact-ruby-v2
6060
"latestby=cvpv&q%5B%5D%5Bpacticipant%5D=Foo+Thing&q%5B%5D%5Bpacticipant%5D=Bar&q%5B%5D%5Bversion%5D=1.2.3&q%5B%5D%5Bversion%5D=4.5.6" =>
6161
"q%5B%5D%5Bpacticipant%5D=Foo%20Thing&q%5B%5D%5Bversion%5D=1.2.3&q%5B%5D%5Bpacticipant%5D=Bar&q%5B%5D%5Bversion%5D=4.5.6&latestby=cvpv",
6262
# pact-ruby-v2 pact (as v2) verified by pact-ruby-v1
63-
"latestby=cvpv&q[][pacticipant]=Foo+Thing&q[][pacticipant]=Bar&q[][version]=1%2e2%2e3&q[][version]=4%2e5%2e6" =>
64-
"q%5B%5D%5Bpacticipant%5D=Foo%20Thing&q%5B%5D%5Bversion%5D=1.2.3&q%5B%5D%5Bpacticipant%5D=Bar&q%5B%5D%5Bversion%5D=4.5.6&latestby=cvpv",
63+
# "latestby=cvpv&q[][pacticipant]=Foo+Thing&q[][pacticipant]=Bar&q[][version]=1%2e2%2e3&q[][version]=4%2e5%2e6" =>
64+
# "q%5B%5D%5Bpacticipant%5D=Foo%20Thing&q%5B%5D%5Bversion%5D=1.2.3&q%5B%5D%5Bpacticipant%5D=Bar&q%5B%5D%5Bversion%5D=4.5.6&latestby=cvpv",
6565

6666
# pact-ruby-v2 pact (as v2) verified by pact-ruby-v2
6767
"latestby=cvpv&q%5B%5D%5Bpacticipant%5D=Foo&q%5B%5D%5Bpacticipant%5D=Bar&q%5B%5D%5Bversion%5D=1.2.3&q%5B%5D%5Bversion%5D=9.9.9" =>
6868
"q%5B%5D%5Bpacticipant%5D=Foo&q%5B%5D%5Bversion%5D=1.2.3&q%5B%5D%5Bpacticipant%5D=Bar&q%5B%5D%5Bversion%5D=9.9.9&latestby=cvpv",
6969
# pact-ruby-v2 pact (as v2) verified by pact-ruby-v1
70-
"latestby=cvpv&q[][pacticipant]=Foo&q[][pacticipant]=Bar&q[][version]=1%2e2%2e3&q[][version]=9%2e9%2e9" =>
71-
"q%5B%5D%5Bpacticipant%5D=Foo&q%5B%5D%5Bversion%5D=1.2.3&q%5B%5D%5Bpacticipant%5D=Bar&q%5B%5D%5Bversion%5D=9.9.9&latestby=cvpv",
70+
# "latestby=cvpv&q[][pacticipant]=Foo&q[][pacticipant]=Bar&q[][version]=1%2e2%2e3&q[][version]=9%2e9%2e9" =>
71+
# "q%5B%5D%5Bpacticipant%5D=Foo&q%5B%5D%5Bversion%5D=1.2.3&q%5B%5D%5Bpacticipant%5D=Bar&q%5B%5D%5Bversion%5D=9.9.9&latestby=cvpv",
7272

7373
# pact-ruby-v2 pact (as v2) verified by pact-ruby-v2
7474
"latestby=cvpv&q%5B%5D%5Blatest%5D=true&q%5B%5D%5Bpacticipant%5D=Foo&q%5B%5D%5Bpacticipant%5D=Bar&q%5B%5D%5Btag%5D=prod&q%5B%5D%5Bversion%5D=1.2.3" =>
7575
"q%5B%5D%5Bpacticipant%5D=Foo&q%5B%5D%5Bversion%5D=1.2.3&q%5B%5D%5Bpacticipant%5D=Bar&q%5B%5D%5Blatest%5D=true&q%5B%5D%5Btag%5D=prod&latestby=cvpv",
7676
# pact-ruby-v2 pact (as v2) verified by pact-ruby-v1
77-
"latestby=cvpv&q[][latest]=true&q[][pacticipant]=Foo&q[][pacticipant]=Bar&q[][tag]=prod&q[][version]=1%2e2%2e3" =>
78-
"q%5B%5D%5Bpacticipant%5D=Foo&q%5B%5D%5Bversion%5D=1.2.3&q%5B%5D%5Bpacticipant%5D=Bar&q%5B%5D%5Blatest%5D=true&q%5B%5D%5Btag%5D=prod&latestby=cvpv",
77+
# "latestby=cvpv&q[][latest]=true&q[][pacticipant]=Foo&q[][pacticipant]=Bar&q[][tag]=prod&q[][version]=1%2e2%2e3" =>
78+
# "q%5B%5D%5Bpacticipant%5D=Foo&q%5B%5D%5Bversion%5D=1.2.3&q%5B%5D%5Bpacticipant%5D=Bar&q%5B%5D%5Blatest%5D=true&q%5B%5D%5Btag%5D=prod&latestby=cvpv",
7979

8080
# pact-ruby-v2 pact (as v2) verified by pact-ruby-v2
8181
"latestby=cvpv&q%5B%5D%5Blatest%5D=true&q%5B%5D%5Bpacticipant%5D=Foo&q%5B%5D%5Bpacticipant%5D=Bar&q%5B%5D%5Bversion%5D=1.2.4" =>
8282
"q%5B%5D%5Bpacticipant%5D=Foo&q%5B%5D%5Bversion%5D=1.2.4&q%5B%5D%5Bpacticipant%5D=Bar&q%5B%5D%5Blatest%5D=true&latestby=cvpv",
8383
# pact-ruby-v2 pact (as v2) verified by pact-ruby-v1
84-
"latestby=cvpv&q[][latest]=true&q[][pacticipant]=Foo&q[][pacticipant]=Bar&q[][version]=1%2e2%2e4" =>
85-
"q%5B%5D%5Bpacticipant%5D=Foo&q%5B%5D%5Bversion%5D=1.2.4&q%5B%5D%5Bpacticipant%5D=Bar&q%5B%5D%5Blatest%5D=true&latestby=cvpv",
84+
# "latestby=cvpv&q[][latest]=true&q[][pacticipant]=Foo&q[][pacticipant]=Bar&q[][version]=1%2e2%2e4" =>
85+
# "q%5B%5D%5Bpacticipant%5D=Foo&q%5B%5D%5Bversion%5D=1.2.4&q%5B%5D%5Bpacticipant%5D=Bar&q%5B%5D%5Blatest%5D=true&latestby=cvpv",
86+
# pact-broker-cli rust rewrite (unordered query params)
87+
"latestby=cvpv&q[][latest]=true&q[][pacticipant]=Foo&q[][tag]=prod&q[][version]=1%2e2%2e3&q[][pacticipant]=Bar" => "q[][pacticipant]=Foo&q[][version]=1%2e2%2e3&q[][pacticipant]=Bar&q[][latest]=true&q[][tag]=prod&latestby=cvpv",
88+
"latestby=cvpv&q[][latest]=true&q[][pacticipant]=Foo&q[][version]=1%2e2%2e4&q[][pacticipant]=Bar" => "q[][pacticipant]=Foo&q[][version]=1%2e2%2e4&q[][pacticipant]=Bar&q[][latest]=true&latestby=cvpv",
89+
"latestby=cvpv&q[][pacticipant]=Foo+Thing&q[][pacticipant]=Bar&q[][version]=1%2e2%2e3&q[][version]=4%2e5%2e6" => "q[][pacticipant]=Foo+Thing&q[][version]=1%2e2%2e3&q[][pacticipant]=Bar&q[][version]=4%2e5%2e6&latestby=cvpv",
90+
"latestby=cvpv&q[][pacticipant]=Foo&q[][pacticipant]=Bar&q[][version]=1%2e2%2e3&q[][version]=4%2e5%2e6" => "q[][pacticipant]=Foo&q[][version]=1%2e2%2e3&q[][pacticipant]=Bar&q[][version]=4%2e5%2e6&latestby=cvpv",
91+
"latestby=cvpv&q[][latest]=true&q[][pacticipant]=Foo&q[][pacticipant]=Bar&q[][tag]=prod&q[][version]=1%2e2%2e3" => "q[][pacticipant]=Foo&q[][version]=1%2e2%2e3&q[][pacticipant]=Bar&q[][latest]=true&q[][tag]=prod&latestby=cvpv",
92+
"latestby=cvpv&q[][latest]=true&q[][pacticipant]=Foo&q[][pacticipant]=Bar&q[][version]=1%2e2%2e4" => "q[][pacticipant]=Foo&q[][version]=1%2e2%2e4&q[][pacticipant]=Bar&q[][latest]=true&latestby=cvpv",
93+
"latestby=cvpv&q[][pacticipant]=Foo&q[][pacticipant]=Bar&q[][version]=1%2e2%2e3&q[][version]=9%2e9%2e9" => "q[][pacticipant]=Foo&q[][version]=1%2e2%2e3&q[][pacticipant]=Bar&q[][version]=9%2e9%2e9&latestby=cvpv"
8694
}
8795

8896
def initialize(app)

spec/service_consumers/pact_helper.rb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,21 @@ def do_not_rollback? _response
4141

4242
app { HalRelationProxyApp.new(app_to_verify) }
4343
app_version ENV["GIT_SHA"] if ENV["GIT_SHA"]
44-
app_version_tags [ENV["GIT_BRANCH"]] if ENV["GIT_BRANCH"]
44+
branch = `git rev-parse --abbrev-ref HEAD`.strip
45+
if branch.start_with?("refs/pull/") || branch.start_with?("HEAD")
46+
branch = ENV["GITHUB_HEAD_REF"] || branch.split("/").last
47+
end
48+
if branch.nil? || branch.empty?
49+
branch = ENV["GIT_BRANCH"]
50+
end
51+
app_version_branch branch
4552
publish_verification_results ENV["CI"] == "true"
4653

47-
if ENV.fetch("PACTFLOW_PACT_FOUNDATION_TOKEN", "") != ""
54+
if ENV.fetch("PACT_BROKER_TOKEN", "") != ""
4855
honours_pacts_from_pact_broker do
49-
pact_broker_base_url "https://pact-foundation.pactflow.io", token: ENV["PACTFLOW_PACT_FOUNDATION_TOKEN"]
56+
pact_broker_base_url ENV.fetch("PACT_BROKER_BASE_URL", ""), token: ENV["PACT_BROKER_TOKEN"]
5057
consumer_version_selectors [
51-
{ tag: "master", latest: true }
58+
{ mainBranch: true }, { deployed: true },
5259
]
5360
enable_pending true
5461
include_wip_pacts_since "2000-01-01"
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
require "spec/support/test_data_builder"
2+
require_relative "shared_provider_states"
3+
4+
Pact.provider_states_for "pact-broker-cli" do
5+
shared_provider_states
6+
shared_noop_provider_states
7+
8+
9+
10+
11+
provider_state "a pact between Condor and the Pricing Service exists with branch main" do
12+
set_up do
13+
TestDataBuilder.new
14+
.create_condor
15+
.create_consumer_version("1.3.0", branch: "main")
16+
.create_pricing_service
17+
.create_pact
18+
end
19+
end
20+
21+
provider_state "a pact between Condor and the Pricing Service exists with branch feature" do
22+
set_up do
23+
TestDataBuilder.new
24+
.create_condor
25+
.create_consumer_version("1.3.0", branch: "feature")
26+
.create_pricing_service
27+
.create_pact
28+
end
29+
end
30+
31+
provider_state "version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 of pacticipant Foo exists with a test environment available for release" do
32+
set_up do
33+
TestDataBuilder.new
34+
.create_environment("test", uuid: "16926ef3-590f-4e3f-838e-719717aa88c9")
35+
.create_consumer("Foo")
36+
.create_consumer_version("5556b8149bf8bac76bc30f50a8a2dd4c22c85f30")
37+
end
38+
end
39+
40+
provider_state "version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 of pacticipant Foo exists with a test environment is released with id ff3adecf-cfc5-4653-a4e3-f1861092f8e0" do
41+
set_up do
42+
TestDataBuilder.new
43+
.create_environment("test", uuid: "16926ef3-590f-4e3f-838e-719717aa88c9")
44+
.create_consumer("Foo")
45+
.create_consumer_version("5556b8149bf8bac76bc30f50a8a2dd4c22c85f30")
46+
.create_released_version_for_consumer_version(uuid: "ff3adecf-cfc5-4653-a4e3-f1861092f8e0", environment_name: "test")
47+
end
48+
end
49+
50+
provider_state "version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 of pacticipant Foo exists with a test environment available for deployment" do
51+
set_up do
52+
TestDataBuilder.new
53+
.create_consumer("Foo")
54+
.create_consumer_version("5556b8149bf8bac76bc30f50a8a2dd4c22c85f30")
55+
.create_environment("test", uuid: "16926ef3-590f-4e3f-838e-719717aa88c9")
56+
end
57+
end
58+
end

spec/service_consumers/shared_provider_states.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,4 +400,20 @@ def shared_noop_provider_states
400400
no_op
401401
end
402402

403+
provider_state "the pb:latest-pact-versions relation exists in the index resource" do
404+
no_op
405+
end
406+
407+
provider_state "the pb:pacticipants relation exists in the index resource" do
408+
no_op
409+
end
410+
411+
provider_state "the pb:pacticipant relation exists in the index resource" do
412+
no_op
413+
end
414+
415+
provider_state "a webhook with uuid non-existent-uuid does not exist" do
416+
no_op
417+
end
418+
403419
end

0 commit comments

Comments
 (0)