Joel Whalen
11/09/2023, 4:48 PMVerifier
callback don't actually print when there's a failure, so how do I inspect the results?
import { Verifier } from '@pact-foundation/pact'
const { API_URL, PACTFLOW_TOKEN } = process.env
const opts = {
providerBaseUrl: API_URL,
pactBrokerUrl: '<https://my-pactflow.pactflow.io/>',
pactBrokerToken: PACTFLOW_TOKEN,
provider: 'normalizer',
consumerVersionTags: ['v2'],
providerVersionTags: ['v1'],
providerVersionBranch: 'my-branch',
providerVersion: 'v1'
}
console.log(opts)
new Verifier(opts).verifyProvider().then(output => {
console.log('Verify provider function')
console.log(output)
})
Joel Whalen
11/09/2023, 4:55 PMrequestFilter
middleware to access the response
requestFilter: (req, res) => {
console.log(res)
}
Joel Whalen
11/09/2023, 5:07 PMrequestFilter
function, my verification test breaks in a different way with the error Request Failed - One or more of the setup state change handlers has failed
How do you all deal with this?Matt (pactflow.io / pact-js / pact-go)
next
which needs to be called as the last thing i.e. next()
(it’s actually just a standard Express middleware, so it needs to return. This is why your state change handlers are failing. See https://github.com/pact-foundation/pact-js/blob/master/docs/provider.md#modify-requests-prior-to-verification-request-filters
2. the new Verifier(opts).verifyProvider().then(…
is a promise - this looks to be dangling (i.e. unhandled), and so it seems possible the test is finishing before the verification can report problems backMatt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
logLevel
property to DEBUG
(or perhaps TRACE
) and see all of the gory detailJoel Whalen
11/09/2023, 10:21 PMJoel Whalen
11/09/2023, 10:22 PMMatt (pactflow.io / pact-js / pact-go)
Joel Whalen
11/09/2023, 10:24 PMJoel Whalen
11/10/2023, 3:18 PMres
or req
objects are huge and don't seem to contain the headers or body detailed in the pact. For example, these are my print statements
requestFilter: (req, res, next) => {
req.headers['Authorization'] = `Bearer ${jwtGenerator()}`
console.log(req.headers)
console.log(req.body)
next()
},
but the req.body
isn't what I'm expecting at all (it should be an address object)
{
'content-type': 'application/json',
accept: '*/*',
'accept-encoding': 'gzip, deflate',
host: '127.0.0.1:34111',
'content-length': '76',
Authorization: 'Bearer my-correct-token-here'
}
{
action: 'teardown',
params: {},
state: 'I am able to normalize addresses'
}
Joel Whalen
11/10/2023, 3:23 PM1) Verifying a pact between flow-controller and normalizer Given I am able to normalize addresses - a request to normalize an address
1.1) has a matching body
/ -> Expected body Present(1698 bytes) but was empty
1.2) has status code 200
expected 200 but was 204
1.3) includes header 'Accept' with value '"application/json"'
Expected header 'Accept' to have value '"application/json"' but was ''
Expected header 'Content-Type' to have value '"application/json"' but was ''
I'd like to see the full response to figure out why it returned 204, especially since when I open up my running server logs I don't see a 204 status code anywhere, just 401 unauthorizedJoel Whalen
11/10/2023, 3:24 PMreq
and res
objects... I was looking at the wrong one. Ok slowly starting to wrap my head around this....Matt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
I’d like to see the full response to figure out why it returned 204, especially since when I open up my running server logs I don’t see a 204 status code anywhere, just 401 unauthorizedhmm perhaps it’s
TRACE
logs that log the full request/response.Matt (pactflow.io / pact-js / pact-go)
[12:26:29.534] DEBUG (99705): pact@11.0.2: incoming request: {"body":{},"headers":{"accept":"text/plain","authorization":"Bearer token","accept-encoding":"gzip, deflate","host":"127.0.0.1:50430"},"method":"GET","path":"/animals/100"}
Middleware invoked before provider API - injecting Authorization token
[12:26:29.536] DEBUG (99705): pact@11.0.2: Proxying GET: /animals/100
[12:26:29.544] DEBUG (99705): pact@11.0.2: outgoing response: {"body":"id=100;first_name=Nanny;last_name=Doe;animal=goat","headers":{"x-powered-by":"Express","access-control-allow-origin":"*","content-type":"text/plain; charset=utf-8","date":"Mon, 13 Nov 2023 01:26:29 GMT","connection":"close","content-length":"49"},"status":200}
Joel Whalen
11/13/2023, 8:10 PMJoel Whalen
11/13/2023, 8:14 PM2023-11-13T20:12:39.610158Z INFO ThreadId(11) pact_verifier::pact_broker: Fetching path '/pacts/provider/normalizer/for-verification' from pact broker
2023-11-13T20:12:40.250435Z ERROR ThreadId(11) pact_verifier: No pacts found matching the given consumer version selectors in pact broker '<https://my-broker.pactflow.io/>': Link/Resource was not found - No pacts were found for this provider
In the broker, the consumer version has been published as 1.0.0
, and my verification looks like this
new Verifier({
providerBaseUrl: API_URL,
pactBrokerUrl: '<https://my-broker.pactflow.io/>',
pactBrokerToken: PACTFLOW_TOKEN,
provider: 'normalizer',
consumerVersionTags: ['1.0.0'],
providerVersionTags: ['v1'],
providerVersionBranch: 'my-branch',
providerVersion: 'v1',
// logLevel: 'trace',
//@ts-ignore
requestFilter: (req, res, next) => {
req.headers['Authorization'] = `Bearer ${jwtGenerator()}`
console.log(res.statusCode)
console.log(req.headers)
next()
}
})
.verifyProvider()
.then(output => {
console.log('Verify provider function')
console.log(output)
})
Did I specify the consumerVersionTags
list incorrectly?Matt (pactflow.io / pact-js / pact-go)
consumerVersionTags: ['1.0.0'],
Similarly, this should be one ore more tags to apply to the provider _version (_which is v1
) upon verification. It would then tag it as v1
as well, which is probably not what you want
providerVersionTags: ['v1'],
You should be avoiding tags though and using branches/environments/releases instead:
• https://docs.pact.io/pact_broker/branches
• https://docs.pact.io/pact_broker/recording_deployments_and_releasesJoel Whalen
11/13/2023, 9:07 PMMatt (pactflow.io / pact-js / pact-go)
Joel Whalen
11/13/2023, 9:09 PMJoel Whalen
11/13/2023, 9:09 PMMatt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Joel Whalen
11/13/2023, 9:19 PMJoel Whalen
11/14/2023, 3:06 PM--branch=main
property, but still getting this failure on verification
2023-11-14T15:05:11.303680Z INFO ThreadId(11) pact_verifier::pact_broker: Fetching path '/' from pact broker
2023-11-14T15:05:12.241720Z INFO ThreadId(11) pact_verifier::pact_broker: Fetching path '/pacts/provider/normalizer/for-verification' from pact broker
2023-11-14T15:05:13.544083Z INFO ThreadId(11) pact_verifier::pact_broker: error response for pacts for verification: failed validation - ["consumerVersionSelectors: must specify a value for environment or tag or branch, or specify mainBranch=true, matchingBranch=true, latest=true, deployed=true, released=true or deployedOrReleased=true (at index 2)"]
2023-11-14T15:05:13.544474Z ERROR ThreadId(11) pact_verifier: No pacts found matching the given consumer version selectors in pact broker '<https://updaterinc.pactflow.io/>': failed validation - ["consumerVersionSelectors: must specify a value for environment or tag or branch, or specify mainBranch=true, matchingBranch=true, latest=true, deployed=true, released=true or deployedOrReleased=true (at index 2)"]
2023-11-14T15:05:13.544587Z ERROR ThreadId(11) pact_verifier: Failed to load pact - No pacts found matching the given consumer version selectors in pact broker '<https://updaterinc.pactflow.io/>'
The error message is saying to setup my consumerVersionSelectors, but I have, and they look like this
consumerVersionSelectors: [
{ mainBranch: true },
{ matchingBranch: true },
{ consumer: 'flow-controller' },
{ branch: 'main' }
]
Matt (pactflow.io / pact-js / pact-go)
providerBranch
set (on the VerifierOptions
type)? I think possibly, matchingBranch
validation is failing because it doesn’t know the provider’s branch. We could possibly improve the client side validation in this case (and also the error message coming from the broker, which isn’t helpful in this case)Joel Whalen
11/15/2023, 2:33 PMproviderVersionBranch
set. Ok so I set providerBranch
but still getting the same errorJoel Whalen
11/15/2023, 3:08 PMJoel Whalen
11/15/2023, 3:35 PMconsumerVersionSelectors
object
{
providerBaseUrl: API_URL,
pactBrokerUrl: '<https://updaterinc.pactflow.io/>',
pactBrokerToken: PACTFLOW_TOKEN,
// pactUrls: ['./src/flow-controller-normalizer.json'],
provider: 'normalizer',
providerVersionBranch: 'UCS-779-verify-normalizer',
providerVersion: '8edfcd4984a01a823b0b56e5ee8c306d847751e0',
consumerVersionSelectors: [
// { mainBranch: true },
// { matchingBranch: true },
// { consumer: 'flow-controller' },
{ branch: 'main' }
],
//@ts-ignore
requestFilter: (req, res, next) => {
req.headers['Authorization'] = `Bearer ${jwtGenerator()}`
next()
}
}
Matt (pactflow.io / pact-js / pact-go)
mainBranch
doesn’t work 🤔Matt (pactflow.io / pact-js / pact-go)
providerVersionBranch
. Either should work thoughJoel Whalen
11/15/2023, 11:06 PMMatt (pactflow.io / pact-js / pact-go)
Joel Whalen
11/16/2023, 12:14 AMconsumer-app-version
in ci? I thought if I had the --branch
flag I wouldn't need to use this?
No value provided for required options '--consumer-app-version'
Joel Whalen
11/16/2023, 12:14 AMJoel Whalen
11/16/2023, 12:15 AMMatt (pactflow.io / pact-js / pact-go)
branch
is more to indicate the feature/line of work happening. The version is extremely important, because that uniquely identifies the piece of software that is being changed/deployed/verified etc.