So I am using the gorilla mux package and I wish I can show the full test case but unfortunately the test case has too many lines of code to even fit it here because the expected result is a big json returned.
I know my expected should be equal to the actual but it seems that when running the unit test it does not work.
func TestHealthCheckHandler(t *testing.T) {
req, err := http.NewRequest("GET", "/health", nil)
if err != nil {
t.Fatal(err)
}
rr := httptest.NewRecorder()
handler := http.HandlerFunc(HealthCheckHandler)
handler.ServeHTTP(rr, req)
if status := rr.Code; status != http.StatusOK {
t.Errorf("handler returned wrong status code: got %v want %v",
status, http.StatusOK)
}
expected := `{"alive": true}`
if rr.Body.String() != expected {
t.Errorf("handler returned unexpected body: got %v want %v", rr.Body.String(), expected)
}
}
for a lack of showing my code cause it’s too long, here’s the format for what it should look like. Ideally, I cannot get my expected to equal to rr.Body.String() even though I know they are equal. I am thinking it has something to do with whitespacing… How can I fix this?