Skip to content

Instantly share code, notes, and snippets.

@rugwirobaker
Created October 4, 2018 11:04
Show Gist options
  • Save rugwirobaker/0064a192ad7f189efab77ce61256ba7b to your computer and use it in GitHub Desktop.
Save rugwirobaker/0064a192ad7f189efab77ce61256ba7b to your computer and use it in GitHub Desktop.
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