hello, I am trying to publish pact file created lo...
# pact-net
p
hello, I am trying to publish pact file created locally to my pactflow account. But looks like I need "pactfoundation/pact-cli:latest" docker image running to talk to broker for Pact Net 4.x.x onwards, is there any documentation or code example on how to do that? Any help will be greatly appreciated, thanks
y
Hey here is 4 ways you can publish to the pactflow broker https://docs.pactflow.io/docs/bi-directional-contract-testing/contracts/oas#publishing-the-provider-contract--results-to-pactflow The command will be pact-broker publish :)
p
thanks for replying Yousaf, so i did pull the pact cli docker and tried the below, it keeps failing for me
Copy code
C:\Users\<myUserName>\source\repos\PACT\pacts> docker run --rm pactfoundation/pact-cli:latest broker publish "ApiClient-EmployeeList.json" -b="https://<org_name>.<http://pactflow.io|pactflow.io>" -k="<tokenValue>" -a="1.0.0"
Specified pact file 'ApiClient-EmployeeList.json' does not exist. This sometimes indicates one of the arguments has been specified with the wrong name and has been incorrectly identified as a file path.
I keep getting the same, note that i am already in the directory where this contract json exists.
any ideas here, i am sure i am doing something silly here
y
You need to load your pacts into your docker image with a volume mount. You will probably find the pact ruby standalone easiest to use that will pick up the file or a folder of pact files.
p
many thanks Yousaf, I am now able to upload the file through the cli, for others benefit, I ran the below command after pulling the docker image
Copy code
> docker run --rm -v c:/Users/<MyUser>/source/repos/PACT/pacts:/var/lib/pacts pactfoundation/pact-cli:latest publish "/var/lib/pacts/ApiClient-EmployeeList.json" -b="https://<MyOrgName>.<http://pactflow.io|pactflow.io>" -k="<tokenValue>" -a="1.0.0"
But the issue now is, contract uploaded is NOT being verified after I run the test below, what am I doing wrong, any ideas please?
Copy code
var config = new PactVerifierConfig
        {
            LogLevel = PactLogLevel.Information,
            Outputters = new List<IOutput>
            {
                new XUnitOutput(_output)
            }
        };
        
        IPactVerifier verifier = new PactVerifier(config);
        verifier.ServiceProvider("EmployeeList", new Uri("<http://localhost:5008>"))
            .WithPactBrokerSource(new Uri("https://<MyOrg>.<http://pactflow.io|pactflow.io>"), options =>
            {
                options
                    .TokenAuthentication("<TokenValue>")
                    .ConsumerVersionSelectors(new ConsumerVersionSelector { MainBranch = true, Latest = true })
                    .PublishResults("1.0.0", results =>
                    {
                        results
                            .ProviderBranch("master")
                            .BuildUri(new Uri("https://<MyOrg>.<http://pactflow.io/pacts/provider/EmployeeList/consumer/ApiClient/latest%22|pactflow.io/pacts/provider/EmployeeList/consumer/ApiClient/latest">));
                    });
            })
            .WithProviderStateUrl(new Uri("<http://localhost:5008>"+ "/employees"))
            .Verify();
the broker UI on the link i have used
and the logs from run (copied from Rider)
Copy code
PactNet.Exceptions.PactFailureException: Pact verification failed

PactNet.Exceptions.PactFailureException
Pact verification failed
   at PactNet.Verifier.InteropVerifierProvider.Execute()
   at PactNet.Verifier.PactVerifierSource.Verify()
   at ContractTestV2.Tests.ProviderPactTests.VerifyLatestPacts() in C:\Users\<>\source\repos\ContractTest\ContractTestV2\Tests\ProviderPactTests.cs:line 34



Starting verification...
Pact verification failed

Verifier Output
---------------

Failures:

1) Failed to load pact - Could not load pacts from the pact broker 'https://<>.<http://pactflow.io/|pactflow.io/>' - ContentError("Request to pact broker URL 'https://<>.<http://pactflow.io/pacts/provider/EmployeeList/for-verification|pactflow.io/pacts/provider/EmployeeList/for-verification>' failed - HTTP status client error (400 Bad Request) for url (https://<>.<http://pactflow.io/pacts/provider/EmployeeList/for-verification|pactflow.io/pacts/provider/EmployeeList/for-verification>)")


There were 1 pact failures

Verifier Logs
-------------
[INFO][pact_verifier::pact_broker] Fetching path '/' from pact broker
[WARN][rustls::check] Received a ServerHelloDone handshake message while expecting [CertificateRequest]
[INFO][pact_verifier::pact_broker] Fetching path '/pacts/provider/EmployeeList/for-verification' from pact broker
[ERROR][pact_verifier] Failed to load pact - \x1b[31mCould not load pacts from the pact broker 'https://<>.<http://pactflow.io/|pactflow.io/>' - ContentError("Request to pact broker URL 'https://<>.<http://pactflow.io/pacts/provider/EmployeeList/for-verification|pactflow.io/pacts/provider/EmployeeList/for-verification>' failed - HTTP status client error (400 Bad Request) for url (https://<>.<http://pactflow.io/pacts/provider/EmployeeList/for-verification|pactflow.io/pacts/provider/EmployeeList/for-verification>)")\x1b[0m
[WARN][pact_matching::metrics] 

Please note:
We are tracking events anonymously to gather important usage statistics like Pact version and operating system. To disable tracking, set the 'PACT_DO_NOT_TRACK' environment variable to 'true'.
any help on above will be greatly appreciated @Yousaf Nabi (pactflow.io) thanks
m
Can you please enable debug level logging and share?
p
where can i do that? sorry i have just started using it
m
I don’t know Pact .NET very well, but a search of the pact net docs at docs.pact.io or the project repo should yield results.
p
ah got it, is that right?
Copy code
var config = new PactVerifierConfig
        {
            LogLevel = PactLogLevel.Debug,
m
looks about right!
also
BuildUri
is meant to point to the URL of your build (e.g. Github or jenkins build) not the pact file
Copy code
.ConsumerVersionSelectors(new ConsumerVersionSelector { MainBranch = true, Latest = true })
I could be wrong, but it doesn’t look like there are any pacts marked as the main branch, so perhaps it’s not finding any pacts (using your screenshot)
p
I dont have the integration from a pipeline yet, I created pact locally from consumer, uploaded it using pact cli and now running the provider test to verify the interaction, so what should this value be?
m
In your case, you haven’t tagged, deployed or marked the contract with a tag/branch
So
latest
is about the only option available to you
see the CI/CD workshop in 👇 (howtolearn) for an ideal setup
s
Here are a number of useful hands-on labs that teach all of the key concepts: https://docs.pactflow.io/docs/workshops and https://docs.pact.io/implementation_guides/workshops
p
Hi Matt, with all the suggested changes it works (I literally deleted buildUri & other info bits for now). Many thanks for all the support! 💯
y
Woohoo glad you are sorted @pooja sharma 🙌
1
p
@Yousaf Nabi (pactflow.io) work in progress .. but for now Indeed 🙂 hope not to bother too much in near future 🤪
y
Well, glad you are sorted for now, and don't worry about bothering us, it is what we are here for
🙌 1
Would love feedback over the course of your experience with Pact/Pactflow and look to improve ares where we can. Thanks @pooja sharma
p
on the note of feedback, just something I observed, (but its not blocking me right now)
thank you 1
y
it should be
broker can-i-deploy
or
pact-broker can-i-deploy
(to align the docker version with the ruby and standalone CLI)
p
so silly of me, thanks so much 🙂