I have the following function:
func SomeFunction(w http.ResponseWriter, ...) error{
.
.
.
return json.NewEncoder(w).Encode(&c)
}
where c is my struct. When I run the function I receive the response body with a json but I can't test this function. For example, I have:
func TestSomeFunction(t *testing.T) {
.
.
.
w := httptest.ResponseRecorder{}
err := SomeFunction(w, ...)
.
.
}
My w.Body is empty in this case. The problem isn't my function because I when I run I get the body. I think I'm not testing in the right way. How is the right way to test it?