Slide 4
Slide 4 text
例えばこんなコード
type MyHandler struct{}
func (h *MyHandler) Sample(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("sample"))
w.WriteHeader(http.StatusTeapot)
}
func Test(t *testing.T) {
req := httptest.NewRequest(http.MethodGet, "/", nil)
res := httptest.NewRecorder()
h := &MyHandler{}
h.Sample(res, req)
if res.Code != http.StatusTeapot {
t.Errorf("status code got %d, should be %d", res.Code, http.StatusTeapot)
}
}
=== RUN Test
main_test.go:40: status code got 200, should be 418
--- FAIL: Test (0.00s)