package main import ( "net/http" "net/http/httptest" "testing" ) func TestHelloHandler(t *testing.T) { req, err := http.NewRequest("GET", "/hello", nil) if err != nil { t.Fatal(err) } rr := httptest.NewRecorder() handler := http.HandlerFunc(helloHandler) handler.ServeHTTP(rr, req) expected := "hello world\n" if rr.Body.String() != expected { t.Errorf("handler returned unexpected body: got %v want %v", rr.Body.String(), expected) } }