Skip to content

Instantly share code, notes, and snippets.

Created October 4, 2018 11:04
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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(, 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment