func TestGetProduct(t *testing.T) {
clearTable()
addProduct("keyboard", 100, 5001.00)
request, err := http.NewRequest("GET", "/product/1", nil)
if err != nil {
log.Println(err.Error())
} else {
log.Println("no error")
}
response := sendRequest(request)
checkStatusCode(t, http.StatusOK, response.Code)
}
func sendRequest(request *http.Request) *httptest.ResponseRecorder {
recorder := httptest.NewRecorder()
a.Router.ServeHTTP(recorder, request)
return recorder
}
func checkStatusCode(t *testing.T, expectedStatusCode int, actualStatusCode int) {
if expectedStatusCode != actualStatusCode {
t.Errorf("Expected Status: %v, Received: %v", expectedStatusCode, actualStatusCode)
} else {
log.Printf("Received Status Code: %v", actualStatusCode)
}
}
I’m able to add a product into my table, but getting status code 500.
Where I’m getting this wrong?