Need Clarification on this: According to the Pact-...
# pact-go
s
Need Clarification on this: According to the Pact-Go instructions, we must have our provider API running in the background in order to perform provider verification. Additionally, I could see in the example that there is code to start the server as well as for the API handler. However, in one of the videos I watched about adding provider verification in go, the person didn't set up a mock server. I'm confused. Do we need to set up a mock server in the test.go file for provider verification, or could I just leave my backend server running in the background and pact will pull API details from the contract, make the request, and validate the response received against what we have in the contract since we are providing pactUrls in the pact.VerifyProvider or something else?
m
The mock server is only used in the consumer test
could I just leave my backend server running in the background and pact will pull API details from the contract, make the request, and validate the response received against what we have in the contract since we are providing pactUrls in the pact.VerifyProvider or something else? (
Yes exactly, this is what you do for the provider test.
Start your local provider and point Pact at it, and tell Pact where to find the contracts (e.g. from local files, but more likely from a Pact Broker / Pactflow)
s
Okiee thanks..
👍 1
m
There is a go workshop available and examples if you’d like to look at those
see howtoexamples
s
m
and howtolearn
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
s
just curious though, why are starting the server and adding api route handler in the below example.. could you please clarify that? https://github.com/pact-foundation/pact-go/blob/master/examples/provider_test.go
m
what additional route?
s
m
just curious though, why are starting the server and adding api route handler in the below example.. could you please clarify that?
in that example, that is the API provider. You have to run the provider for the pact test to work
the consumer needs that route to work, which is why it’s in the consumer test
s
owww...thankss...
👍 1
m
1. Write a unit test of your Consumer API client, using Pact to mock the provider 2. This should generate a pact file, which you should upload to a pact broker / Pactflow 3. Write a provider test that fetches the pacts, and replays the request against your real provider (running locally, stubbing out dependencies)
👍 2