HTTP Testing
58
func TestAuthenticate(t *testing.T) {!
addUser("Sau Sheong", "
[email protected]",
"password")!
router := httprouter.New()!
router.POST("/login", authenticate) !
writer := httptest.NewRecorder()!
body :=
strings.NewReader("
[email protected]&password=pa
ssword")!
request, _ := http.NewRequest("POST", "/login", body)!
request.Header.Add("Content-Type", "application/x-www-
form-urlencoded")!
router.ServeHTTP(writer, request)!
...!
if !strings.HasPrefix(writer.Header().Get("Set-
Cookie"), "pixelate_cookie") {!
t.Errorf("Cookie not set")!
}!
}