Skip to content

Commit

Permalink
feat: correctly publish self verification results
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Sep 5, 2023
1 parent 903a922 commit e85e5a3
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 18 deletions.
17 changes: 15 additions & 2 deletions doc/pacts/markdown/Pact Broker Client - Pactflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ Upon receiving **a request to publish a provider contract** from Pact Broker Cli
"content": "LS0tCnNvbWU6IGNvbnRyYWN0Cg==",
"contentType": "application/yaml",
"specification": "oas",
"verificationResults": {
"selfVerificationResults": {
"success": true,
"content": "c29tZSByZXN1bHRz",
"contentType": "text/plain",
Expand All @@ -248,7 +248,20 @@ PactFlow will respond with:
"text": "some notice",
"type": "info"
}
]
],
"_embedded": {
"version": {
"number": "1"
}
},
"_links": {
"pb:pacticipant-version-tags": [
{
}
],
"pb:branch-version": {
}
}
}
}
```
2 changes: 1 addition & 1 deletion lib/pactflow/client/provider_contracts/publish.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def contract_params
}.compact

if verification_results_params.any?
contract_params[:verificationResults] = verification_results_params
contract_params[:selfVerificationResults] = verification_results_params
end

{
Expand Down
81 changes: 81 additions & 0 deletions script/foo-bar.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"consumer": {
"name": "Foo"
},
"provider": {
"name": "Bar"
},
"interactions": [
{
"description": "a request to list the latest pacts",
"providerState": "a pact between Condor and the Pricing Service exists",
"request": {
"method": "get",
"path": "/pacts/latest",
"headers": {
}
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/hal+json"
},
"body": {
"_links": {
"self": {
"href": "http://example.org/pacts/latest"
}
},
"pacts": [
{
"_links": {
"self": [
{
"href": "http://example.org/pacts/provider/Pricing%20Service/consumer/Condor/latest"
},
{
"href": "http://example.org/pacts/provider/Pricing%20Service/consumer/Condor/version/1.3.0"
}
]
},
"_embedded": {
"consumer": {
"name": "Condor",
"_links": {
"self": {
"href": "http://example.org/pacticipants/Condor"
}
},
"_embedded": {
"version": {
"number": "1.3.0"
}
}
},
"provider": {
"_links": {
"self": {
"href": "http://example.org/pacticipants/Pricing%20Service"
}
},
"name": "Pricing Service"
}
}
}
]
},
"matchingRules": {
"$.headers.Content-Type": {
"match": "regex",
"regex": "application\\/hal\\+json"
}
}
}
}
],
"metadata": {
"pactSpecification": {
"version": "2.0.0"
}
}
}
18 changes: 8 additions & 10 deletions script/publish-pact.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export PACT_BROKER_BASE_URL="http://localhost:9292"
export PACT_BROKER_TOKEN="localhost"
export PACT_BROKER_BASE_URL=${PACT_BROKER_BASE_URL:-"http://localhost:9292"}
export PACT_BROKER_TOKEN=${PACT_BROKER_TOKEN:-"localhost"}
#export PACT_BROKER_FEATURES=publish_pacts_using_old_api

# bundle exec bin/pact-broker create-or-update-webhook http://localhost:9393 \
Expand All @@ -8,11 +8,11 @@ export PACT_BROKER_TOKEN="localhost"
# --description "foo webhook" \
# --contract-published

bundle exec bin/pact-broker create-or-update-webhook http://localhost:9393 \
--uuid d40f38c3-aaa3-47f5-9161-95csfadfsd7 \
--description "This is quite a long description for a webhook that I hope will be truncated" \
--request POST \
--contract-published
# bundle exec bin/pact-broker create-or-update-webhook http://localhost:9393 \
# --uuid d40f38c3-aaa3-47f5-9161-95csfadfsd7 \
# --description "This is quite a long description for a webhook that I hope will be truncated" \
# --request POST \
# --contract-published

# bundle exec bin/pact-broker publish spec/pacts/pact_broker_client-pact_broker.json spec/fixtures/foo-bar.json \
# --consumer-app-version 1.2.12 \
Expand All @@ -29,10 +29,8 @@ bundle exec bin/pact-broker create-or-update-webhook http://localhost:9393 \
# --contract-published


bundle exec bin/pact-broker publish spec/pacts/pact_broker_client-pact_broker.json \
bundle exec bin/pact-broker publish scripts/foo-bar.json \
--consumer-app-version 1.2.26 \
--broker-base-url http://localhost:9292 \
--broker-token localhost \
--auto-detect-version-properties \
--build-url http://mybuild \
--branch master --tag foo5 --tag foo6
Expand Down
2 changes: 1 addition & 1 deletion script/publish-provider-contract.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export PACT_BROKER_BASE_URL=${PACT_BROKER_BASE_URL:-"http://localhost:9292"}
bundle exec bin/pactflow publish-provider-contract \
script/oas.yml \
--provider Foo \
--provider Bar \
--provider-app-version 1013b5650d61214e19f10558f97fb5a3bb082d44 \
--branch main \
--tag dev \
Expand Down
17 changes: 15 additions & 2 deletions spec/pacts/pact_broker_client-pactflow.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"content": "LS0tCnNvbWU6IGNvbnRyYWN0Cg==",
"contentType": "application/yaml",
"specification": "oas",
"verificationResults": {
"selfVerificationResults": {
"success": true,
"content": "c29tZSByZXN1bHRz",
"contentType": "text/plain",
Expand All @@ -78,7 +78,20 @@
"text": "some notice",
"type": "info"
}
]
],
"_embedded": {
"version": {
"number": "1"
}
},
"_links": {
"pb:pacticipant-version-tags": [
{
}
],
"pb:branch-version": {
}
}
},
"matchingRules": {
"$.body.notices": {
Expand Down
22 changes: 20 additions & 2 deletions spec/service_providers/pactflow_publish_provider_contract_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"content" => "LS0tCnNvbWU6IGNvbnRyYWN0Cg==",
"contentType" => "application/yaml",
"specification" => "oas",
"verificationResults" => {
"selfVerificationResults" => {
"success" => true,
"content" => "c29tZSByZXN1bHRz",
"contentType" => "text/plain",
Expand All @@ -54,12 +54,30 @@
end

let(:response_status) { 200 }

# Can't tell from the response if the buildUrl was correct, but it's not that important
# Add some assertions to the body to ensure we have called the endpoint correctly,
# not because we use the properties in the CLI output.
# There is unfortunately no good way to determine from the response whether or not
# we have correctly published the self verification results.
let(:success_response) do
{
status: response_status,
headers: pact_broker_response_headers,
body: {
"notices" => Pact.each_like("text" => "some notice", "type" => "info")
"notices" => Pact.each_like("text" => "some notice", "type" => "info"),
"_embedded" => {
"version" => {
# This tells us we have set the version number correctly
"number" => "1"
}
},
"_links" => {
# The links tell us we have successfully created the tags, but we don't care about the contents
"pb:pacticipant-version-tags" => [{}],
# The link tells us we have successfully created the branch version, but we don't care about the contents
"pb:branch-version" => {},
}
}
}
end
Expand Down

0 comments on commit e85e5a3

Please sign in to comment.