Bruno Holanda
01/17/2024, 11:14 PMfunc TestProductAPIProvider(t *testing.T) {
go startServer()
verifier := provider.NewVerifier()
f := func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
log.Println("Alterando Response")
requestFilterCalled = true
next.ServeHTTP(w, r)
})
}
err := verifier.VerifyProvider(t, provider.VerifyRequest{
ProviderBaseURL: "<http://127.0.0.1:8001>",
Provider: "PactGoProductAPI",
ProviderVersion: "v1",
PactFiles: []string{
filepath.ToSlash(fmt.Sprintf("%s/PactGoProductAPIConsumer-PactGoProductAPI.json", pactDir)),
},
RequestFilter: f,
PublishVerificationResults: false,
})
assert.NoError(t, err)
assert.True(t, requestFilterCalled)
}
func startServer() {
mux := http.NewServeMux()
mux.HandleFunc("/products/{id}", func(w http.ResponseWriter, req *http.Request) {
w.Header().Add("Content-Type", "application/json")
fmt.Fprintf(w, `
{
"id":10,
"type":"CREDIT_CARD",
"name":"PS5",
"version":"v2"
}`)
})
log.Fatal(http.ListenAndServe("127.0.0.1:8001", mux))
}