Skip to content

Commit 528034c

Browse files
committed
feat(publish test result): allow json test results to be published with the verification result
1 parent 10a6eb9 commit 528034c

File tree

10 files changed

+100
-2
lines changed

10 files changed

+100
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require_relative 'migration_helper'
2+
3+
Sequel.migration do
4+
change do
5+
add_column(:verifications, :test_results, PactBroker::MigrationHelper.large_text_type)
6+
end
7+
end

lib/pact_broker/api/decorators/verification_decorator.rb

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class VerificationDecorator < BaseDecorator
1010
property :success
1111
property :execution_date, as: :verificationDate
1212
property :build_url, as: :buildUrl
13+
property :test_results, as: :testResults
1314

1415
link :self do | options |
1516
{

lib/pact_broker/domain/verification.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require 'pact_broker/db'
22
require 'pact_broker/repositories/helpers'
3+
require 'json'
34

45
module PactBroker
56

@@ -9,6 +10,7 @@ class Verification < Sequel::Model
910
set_primary_key :id
1011
associate(:many_to_one, :pact_version, class: "PactBroker::Pacts::PactVersion", key: :pact_version_id, primary_key: :id)
1112
associate(:many_to_one, :provider_version, class: "PactBroker::Domain::Version", key: :provider_version_id, primary_key: :id)
13+
plugin :serialization, :json, :test_results
1214

1315
def before_create
1416
super

script/foo-bar-verification.json

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"success": true,
3+
"providerApplicationVersion": "1.0.0",
4+
"testResults": {
5+
"examples": [
6+
{
7+
"description": "has status code 200",
8+
"file_path": "/redacted/.gem/ruby/2.4.1/gems/pact-1.17.0/lib/pact/provider/rspec.rb",
9+
"full_description": "Verifying a pact between me and they Greeting with GET / returns a response which has status code 200",
10+
"id": "/redacted/.gem/ruby/2.4.1/gems/pact-1.17.0/lib/pact/provider/rspec.rb[1:1:1:1:1]",
11+
"line_number": 122,
12+
"pending_message": null,
13+
"run_time": 0.111762,
14+
"status": "passed"
15+
},
16+
{
17+
"description": "has a matching body",
18+
"file_path": "/redacted/.gem/ruby/2.4.1/gems/pact-1.17.0/lib/pact/provider/rspec.rb",
19+
"full_description": "Verifying a pact between me and they Greeting with GET / returns a response which has a matching body",
20+
"id": "/redacted/.gem/ruby/2.4.1/gems/pact-1.17.0/lib/pact/provider/rspec.rb[1:1:1:1:3]",
21+
"line_number": 139,
22+
"pending_message": null,
23+
"run_time": 0.000235,
24+
"status": "passed"
25+
},
26+
{
27+
"description": "has status code 200",
28+
"file_path": "/redacted/.gem/ruby/2.4.1/gems/pact-1.17.0/lib/pact/provider/rspec.rb",
29+
"full_description": "Verifying a pact between me and they Given There is a greeting Provider state success with GET /somestate returns a response which has status code 200",
30+
"id": "/redacted/.gem/ruby/2.4.1/gems/pact-1.17.0/lib/pact/provider/rspec.rb[1:2:1:1:1:1]",
31+
"line_number": 122,
32+
"pending_message": null,
33+
"run_time": 0.006892,
34+
"status": "passed"
35+
},
36+
{
37+
"description": "has a matching body",
38+
"file_path": "/redacted/.gem/ruby/2.4.1/gems/pact-1.17.0/lib/pact/provider/rspec.rb",
39+
"full_description": "Verifying a pact between me and they Given There is a greeting Provider state success with GET /somestate returns a response which has a matching body",
40+
"id": "/redacted/.gem/ruby/2.4.1/gems/pact-1.17.0/lib/pact/provider/rspec.rb[1:2:1:1:1:3]",
41+
"line_number": 139,
42+
"pending_message": null,
43+
"run_time": 0.000176,
44+
"status": "passed"
45+
}
46+
],
47+
"summary": {
48+
"duration": 0.123096,
49+
"errors_outside_of_examples_count": 0,
50+
"example_count": 4,
51+
"failure_count": 0,
52+
"pending_count": 0
53+
},
54+
"summary_line": "4 examples, 0 failures",
55+
"version": "3.7.0"
56+
}
57+
}

script/publish-verification.sh

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
BASE_URL="http://localhost:9292"
2+
3+
response_body=$(curl ${BASE_URL}/pacts/provider/Bar/consumer/Foo/latest)
4+
verification_url=$(echo "${response_body}" | ruby -e "require 'json'; puts JSON.parse(ARGF.read)['_links']['pb:publish-verification-results']['href']")
5+
curl -XPOST -H 'Content-Type: application/json' -d@script/foo-bar-verification.json ${verification_url}

spec/features/publish_verification_spec.rb

+5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@
3333
expect(PactBroker::Domain::Verification.order(:id).last.pact_version_sha).to eq pact.pact_version_sha
3434
end
3535

36+
it "saves the test results" do
37+
subject
38+
expect(PactBroker::Domain::Verification.order(:id).last.test_results).to eq('some' => 'results')
39+
end
40+
3641
it "returns a link to itself that can be followed" do
3742
get_verification_link = parsed_response_body['_links']['self']['href']
3843
get get_verification_link

spec/fixtures/verification.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
22
"success": true,
3-
"providerApplicationVersion": "4.5.6"
3+
"providerApplicationVersion": "4.5.6",
4+
"testResults": {
5+
"some": "results"
6+
}
47
}

spec/lib/pact_broker/api/decorators/verification_decorator_spec.rb

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module Decorators
1212
provider_version_number: "4.5.6",
1313
provider_name: 'Provider',
1414
consumer_name: 'Consumer',
15+
test_results: { 'arbitrary' => 'json' },
1516
build_url: 'http://build-url',
1617
pact_version_sha: '1234',
1718
latest_pact_publication: pact_publication,
@@ -39,6 +40,10 @@ module Decorators
3940
expect(subject[:providerApplicationVersion]).to eq "4.5.6"
4041
end
4142

43+
it "includes the test results" do
44+
expect(subject[:testResults]).to eq(arbitrary: 'json')
45+
end
46+
4247
it "includes the build URL" do
4348
expect(subject[:buildUrl]).to eq "http://build-url"
4449
end

spec/lib/pact_broker/domain/verification_spec.rb

+13
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@ module PactBroker
55
module Domain
66
describe Verification do
77

8+
describe "#save" do
9+
let!(:verification) do
10+
TestDataBuilder.new
11+
.create_pact_with_hierarchy("A", "1", "B")
12+
.create_verification(test_results: {'some' => 'thing'})
13+
.and_return(:verification)
14+
end
15+
16+
it "saves and loads the test_results" do
17+
expect(Verification.find(id: verification.id).test_results).to eq({ 'some' => 'thing' })
18+
end
19+
end
20+
821
describe "#consumer" do
922
let!(:consumer) do
1023
TestDataBuilder.new

spec/support/test_data_builder.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def create_deprecated_webhook_execution params = {}
238238

239239
def create_verification parameters = {}
240240
provider_version_number = parameters[:provider_version] || '4.5.6'
241-
default_parameters = {success: true, number: 1}
241+
default_parameters = {success: true, number: 1, test_results: {some: 'results'}}
242242
parameters = default_parameters.merge(parameters)
243243
parameters.delete(:provider_version)
244244
verification = PactBroker::Domain::Verification.new(parameters)

0 commit comments

Comments
 (0)