I am trying to write a unit test for http.Pusher. I tried using httptest.NewRecorder() as http.ResponseWriter but the type conversion failed. How else can I write the test?
//My function
func push(w http.ResponseWriter, resource string) error {
pusher, ok := w.(http.Pusher)
if ok {
return pusher.Push(resource, nil)
}
return fmt.Errorf("Pusher not supported")
}
//My test
func TestPush(t *testing.T) {
resource := "static/css/main.css"
response := httptest.NewRecorder()
got := push(response, resource)
if got != nil {
t.Errorf("Error : %v", got)
}
}
The output is "Pusher not supported", which I assume that w.(http.Pusher) failed.