This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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