2022-05-28 05:42:28 +03:00
|
|
|
// Copyright 2021 Gin Core Team. All rights reserved.
|
2021-09-06 03:10:06 +03:00
|
|
|
// Use of this source code is governed by a MIT style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2023-03-01 05:03:48 +03:00
|
|
|
//go:build !go1.19
|
2021-09-06 03:10:06 +03:00
|
|
|
|
|
|
|
package gin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"mime/multipart"
|
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2023-03-01 05:03:48 +03:00
|
|
|
func TestContextFormFileFailed18(t *testing.T) {
|
2021-09-06 03:10:06 +03:00
|
|
|
buf := new(bytes.Buffer)
|
|
|
|
mw := multipart.NewWriter(buf)
|
2023-03-01 05:03:48 +03:00
|
|
|
defer func(mw *multipart.Writer) {
|
|
|
|
err := mw.Close()
|
|
|
|
if err != nil {
|
|
|
|
assert.Error(t, err)
|
|
|
|
}
|
|
|
|
}(mw)
|
2021-09-06 03:10:06 +03:00
|
|
|
c, _ := CreateTestContext(httptest.NewRecorder())
|
|
|
|
c.Request, _ = http.NewRequest("POST", "/", nil)
|
|
|
|
c.Request.Header.Set("Content-Type", mw.FormDataContentType())
|
|
|
|
c.engine.MaxMultipartMemory = 8 << 20
|
2023-03-01 05:03:48 +03:00
|
|
|
assert.Panics(t, func() {
|
|
|
|
f, err := c.FormFile("file")
|
|
|
|
assert.Error(t, err)
|
|
|
|
assert.Nil(t, f)
|
|
|
|
})
|
2021-09-06 03:10:06 +03:00
|
|
|
}
|