I'm working in the adoption of Pact in my company, but on Golang, we hit a hurdle on the basic case where a consumer as 2 states for one endpoint:
- Given("A product with id 1 exists").
- Given("A product with id 2 doesn't exists").
Our trouble is on the doesn't exists case.
Consumer
mockProvider.AddInteraction().
Given("The product with ID 66 doesn't exists").
UponReceiving("a request Product 66").
WithRequest(http.MethodGet, S("/api/v1/product/66")).
WillRespondWith(http.StatusNotFound).
Provider
func TestContract(t *testing.T) {
SetLogLevel("TRACE")
verifier := HTTPVerifier{}
err := verifier.VerifyProvider(t, VerifyRequest{
ProviderBaseURL: "http://localhost:8080",
Provider: "ms.pact-provider-example-for-go",
ProviderVersion: "example", // os.Getenv("APP_SHA"),
BrokerURL: "https://…", // os.Getenv("PACT_BROKER_BASE_URL"),
PublishVerificationResults: false,
StateHandlers: StateHandlers{
"A product with id 1 exists": func(setup bool, s ProviderStateV3) (ProviderStateV3Response, error) {
…
return response, nil
},
"A product with id 2 doesn't exists": func(setup bool, s ProviderStateV3) (ProviderStateV3Response, error) {
// ???
},
},
})
require.NoError(t, err)
}
Question
How can we return a bad request reponse as ProviderStateV3Response
is a map interface?