How to create a 'broken' form for testing purposes with http.Client
that will trigger a response error on ParseForm()
in a handler function?
I have the following code:
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
}
...
Then during testing I'm using http.Client
to test this controller:
resp, err = client.PostForm(ts.URL+"/user/signup", url.Values{
"email": {testEmail},
"password": {goodPassword},
)
if err != nil {
t.Error(err) // I never get here
}
Aucun commentaire:
Enregistrer un commentaire