Assertions on request bodies?
bimargulies-google opened this issue · 2 comments
bimargulies-google commented
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?
dlebech commented
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?
bimargulies-google commented
Yes, thanks.