Add a test for issue #56

This commit is contained in:
Daan Sprenkels 2020-05-30 18:04:39 +02:00
parent 2883af7d31
commit 70538f170f

View File

@ -159,3 +159,26 @@ func TestIssue60(t *testing.T) {
srv.ServeHTTP(rr, req)
checkStatusCode(t, rr, http.StatusNotFound)
}
func TestIssue56(t *testing.T) {
srv, _ := createTemporaryRouter(t)
// Make a POST request with both a 'file' *and* a 'shorten' part.
var body bytes.Buffer
form := multipart.NewWriter(&body)
if _, err := form.CreateFormFile("file", "empty.txt"); err != nil {
t.Fatal(err)
}
if _, err := form.CreateFormField("shorten"); err != nil {
t.Fatal(err)
}
form.Close()
req, err := http.NewRequest("POST", "/", bytes.NewReader(body.Bytes()))
if err != nil {
t.Fatal(err)
}
req.Header.Add("Content-Type", form.FormDataContentType())
rr := httptest.NewRecorder()
srv.ServeHTTP(rr, req)
checkStatusCode(t, rr, http.StatusBadRequest)
}