我正在我的公司采用 Pact,但在 Golang 上,我们在基本情况下遇到了障碍,即消费者作为一个端点的 2 个状态:
Given("存在 id 为 1 的产品").
Given("ID 为 2 的产品不存在").
我们的麻烦在于不存在的情况。
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).
供应商
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)
}
问题
我们如何像ProviderStateV3Response地图界面一样返回错误的请求响应?
慕田峪4524236
相关分类