David Kwak
09/26/2022, 6:31 AMpact-go v2.0.0-beta-14
on macOS.
Two questions:
1) Is there something special I have to do to generate a pact file with multiple interactions for a given consumer? I have a consumer test with 3 cases that pass, but the pact file only seems to have the last interaction in the file
2) Is there something special I have to do to generate an interaction entry for a case that returns an error? I have a 404
test case, and the client under test responds to 404
by returning an error, which I check in my test (using the testify/assert.Error
function). This test passes yet doesn’t generate an interaction in a pact file, even when the test is the only one executed.
Any thoughts would be appreciated.Matt (pactflow.io / pact-js / pact-go)
debug
level logs indicate any reason as to why? It’s possible if you use the same description + state it will be overwritten
2. No, it should work as per any other test
Could you please share your test so we can see?David Kwak
09/26/2022, 10:50 PM404
response for the client library resulted in the interaction being recorded. Is there another way to write my test to work with the existing client (I don’t own that code) AND work with pact-go
? I’m a total noob to golang
so I am quite unfamiliar with what is acceptable or not.
a code snippet of the issue
t.Run("404test", func(t *testing.T) {
// mockProvider is instance of consumer.NewV2Pact
mockProvider.
AddInteraction().
Given("resource does not exist")).
UponReceiving("GET for resource").
WithRequest(<GET request>).
WillRespondWith(404)
}
err = mockProvider.ExecuteTest(t, func(config consumer.MockServerConfig) error {
var client Client
client = Client{
ServiceURL: fmt.Sprintf("<http://%s:%d>", config.Host, config.Port),
<additional client config>
}
_, err := client.GetCall(<params>)
assert.Error(t, err)
return err
})
assert.Error(t, err)
})
Matt (pactflow.io / pact-js / pact-go)
ExecuteTest
function accepts a user defined test. If the test errors (i.e. the test did not work as expected) you should return an error. If the error is expected, you should test for that.
I can see you are doing an assert.Error(…)
. That’s probably correct, albeit you might want to check the type of that error, because it could potentially fail for other reasons and give you a false positive.
I would return nil
in the case there is no issue with your test, and the assertions are correct.
Best to talk to somebody who knows this code better though to ensure what is being tested here is correct and validDavid Kwak
09/27/2022, 2:38 AM