Use httptest.NewRecorder to capture the response and httptest.NewRequest to simulate the request, then assert the status code and body.
func TestHandler(t *testing.T) {
req := httptest.NewRequest("GET", "/", nil)
w := httptest.NewRecorder()
handler(w, req)
if w.Code != http.StatusOK {
t.Errorf("handler returned wrong status code: got %v want %v", w.Code, http.StatusOK)
}
}