我正在尝试为 http.Pusher 编写单元测试。我尝试使用 httptest.NewRecorder() 作为 http.ResponseWriter 但类型转换失败。我还能如何编写测试?
//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)
}
}
输出是“不支持 Pusher”,我认为 w.(http.Pusher) 失败了。
潇潇雨雨
相关分类