Closed bimargulies-google closed 6 years ago
It's possible to do assertions in mocks if you define your own response function, for example:
func MyTest(t *testing.T) {
httpmock.RegisterResponder("GET", "https://api.mybiz.com/articles.json",
func(r *http.Request (*http.Response, error) {
if (r.UserAgent() != "agent-007") {
t.Error("Expected Agent 007 as user agent")
}
// More response code
},
)
}
Does this work for your use case?
Yes, thanks.
It would be convenient to have a way to add code to the mock that checks the request and asserts on it. Would you consider patches in this direction?