...
1
2
3
4
5
6
7 package gin
8
9 import (
10 "bytes"
11 "mime/multipart"
12 "net/http"
13 "net/http/httptest"
14 "testing"
15
16 "github.com/stretchr/testify/assert"
17 )
18
19 func TestContextFormFileFailed18(t *testing.T) {
20 buf := new(bytes.Buffer)
21 mw := multipart.NewWriter(buf)
22 defer func(mw *multipart.Writer) {
23 err := mw.Close()
24 if err != nil {
25 assert.Error(t, err)
26 }
27 }(mw)
28 c, _ := CreateTestContext(httptest.NewRecorder())
29 c.Request, _ = http.NewRequest("POST", "/", nil)
30 c.Request.Header.Set("Content-Type", mw.FormDataContentType())
31 c.engine.MaxMultipartMemory = 8 << 20
32 assert.Panics(t, func() {
33 f, err := c.FormFile("file")
34 assert.Error(t, err)
35 assert.Nil(t, f)
36 })
37 }
38
View as plain text