Hi Team, Today when I am trying to do `Provider ve...
# pact-js
h
Hi Team, Today when I am trying to do
Provider verification
(fetching contracts from pact broker) I gets error message: ERROR ThreadId(11) pact_verifier: Failed to load pact - Could not load pacts from the pact broker 'https://rain.pactflow.io' - ContentError("Request to pact broker URL 'https://rain.pactflow.io/pacts/provider/ATP_Provider/for-verification' failed - HTTP status client error (400 Bad Request) for url (https://rain.pactflow.io/pacts/provider/ATP_Provider/for-verification)") To publish the contract I use command
"publish:pact": "pact-broker publish ./pacts --consumer-app-version 1.0.1 --auto-detect-version-properties --broker-base-url=https://**.<http://pactflow.io|pactflow.io> --broker-token=**"
I provide these options to Verifier
const opts = {
provider: "MY_Provider",
logLevel: process.env.LOG_LEVEL,
providerBaseUrl: process.env.BASE_URL,
stateHandlers: {
"when no auth passed": () => {
return Promise.resolve("no token needed");
},
},
pactBrokerUrl: process.env.PACT_BROKER_URL,
pactBrokerToken: process.env.PACT_BROKER_TOKEN,
publishVerificationResult: true,
consumerVersionSelectors: [
{
consumer: "10.0.1",
},
],
providerVersion: "1.0.0",
};
Any clue what I am doing wrong here.
y
You are publishing a contract version with a consumer version of
1.0.1
and using the consumerVersionSelector of
10.0.1
in your provider verification task
h
ohh my bad, @Yousaf Nabi (pactflow.io) you found it very fast, thanks for pointing it.
y
I believe the
consumer
key should have a value which matches the name of the consumer you are interested in. and you should have a key for
version
with
1.0.1
looking at https://docs.pact.io/pact_broker/advanced_topics/consumer_version_selectors
but I may be wrong on that, no worries Heera
m
Can I ask why you're using the consumer version here? It's supported for edge cases but I think it will make your build pipelines very fragile and high maintenance, having to know the versions. Branches and environments are the recommendation
👍 1
y
☝️ There is no branch, nor tag applied at the point of publishing. The consumer property should be the name of the consumer you are targeting, and you required to provide one of the properties in this list, alongside consumer, be it
branch
,
tag
etc
More info on the recommended setup 👍 https://docs.pact.io/provider/recommended_configuration
you should have a key for
version
with
1.0.1
The docs don't actually show you can specify the consumer name with a version number, or that
version
is a supported key in
consumerVersionSelectors
t
doesn’t
--auto-detect-version-properties
apply the branch?
y
ahh yes https://github.com/pact-foundation/pact_broker-client#publish
Copy code
[--auto-detect-version-properties], [--no-auto-detect-version-properties]
              # Automatically detect the repository branch from known CI
                environment variables or git CLI. Supports Buildkite, Circle
                CI, Travis CI, GitHub Actions, Jenkins, Hudson, AppVeyor,
                GitLab, CodeShip, Bitbucket and Azure DevOps.
just checking in the code now, because I don't think it picks up a version, just branch, going by that description. could that be confusing. Would
--auto-detect-branch-properties
be more appropriate, or for it to also include/infer a version property (say from a SHA), unless
--consumer-app-version
is explicitly stated.
@Heera Singh if you try updating your configuration to one of the recommended https://docs.pact.io/pact_broker/advanced_topics/consumer_version_selectors#recommended You should find success 🙂 - I wasn't able to pull down a pact with your setup above with the consumer version selector, but after updating to one of the above setups I was able to
t
I thought auto-detetect-version-properties picked up the sha as the version if you didn’t specify it - but if the code doesn’t say that then I must be mistaken
y
So —consumer-app-version always needs to be set, even with the old and new way of publishing pacts. There is a version_required value that gets calculated but doesn’t look to be used in the new way of publishing unless I am mistaking. You can set the old way with a feature flag. In both cases, I am required to pass in the consumer app version flag Just replying on my phone but will pull up some code refs later against the pact broker client repo
t
oh right. In that case, I think the parameter name is a bit misleading
h
@Yousaf Nabi (pactflow.io) you are correct, you need to use it because its required
No value provided for required options '--consumer-app-version',
As I am not using CI now, It worked me with this minimal configuration, publish contract command
pact-broker publish ./pacts --consumer-app-version 1.0.1 --branch branch1 --broker-base-url=https://**.<http://pactflow.io|pactflow.io> --broker-token=**
and in provider test
consumerVersionSelectors: [
{ consumer: "Order_Consumer", branch: "branch1" },
],
Thanks everyone!