如何创建用于测试目的的“损坏”表单,http.Client
这将在处理程序函数中触发响应错误ParseForm()
?
我有以下代码:
func (app *App) signupUser(w http.ResponseWriter, r *http.Request) {
err := r.ParseForm()
if err != nil { // how to trigger this if statement?
sendStatus(w, http.StatusBadRequest, "error parsing form")
return
}
...
然后在测试期间我http.Client
用来测试这个控制器:
resp, err = client.PostForm(ts.URL+"/user/signup", url.Values{
"email": {testEmail},
"password": {goodPassword},
)
if err != nil {
t.Error(err) // I never get here
}