Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
func TestHandler(t *testing.T) {
testcases := []struct {
name string
request *http.Request
code int
}{
{
name: "Wrong-Method",
request: NewRequest(t, http.MethodGet, "/", nil),
code: 405,
},
}
//Bring your attention here
res := httptest.NewRecorder()
for _, tc := range testcases {
Handler().ServeHTTP(res, tc.request)
t.Run(tc.name, func(t *testing.T) {
t.Run("Assert-Code", func(t *testing.T) {
assertCode(t, res.Code, tc.code)
})
t.Run("Response-Body-Format", func(t *testing.T) {
t.Logf("logging:%s", res.Body.String())
})
})
//And here
res.Flush()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment