Answer the question
In order to leave comments, you need to log in
Testing a Go program?
Good afternoon!
I have written a web service in Go and am writing tests for it. I wrote a test to test the handler but I get an error
package main
import (
"net/http"
"net/http/httptest"
"testing"
)
func TestHealthCheckHandler(t *testing.T) {
req, err := http.NewRequest("POST", "/ad/getall", nil)
if err != nil {
t.Fatal(err)
}
rr := httptest.NewRecorder()
handler := http.HandlerFunc(GetAll)
handler.ServeHTTP(rr, req)
expected := `400`
if rr.Body.String() != expected {
t.Errorf("handler returned unexpected body: got %v want %v",
rr.Body.String(), expected)
}
}
Answer the question
In order to leave comments, you need to log in
The test is written correctly. But the main program, apparently, no. Give the text of main.go.
Well, or look at line No. 80 in it, as the execution stack dump writes.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question