mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-16 13:22:09 +08:00
Run TestContextFormFileFailed17 test if current go version is go1.17 or go1.18
This commit is contained in:
parent
a2a2dfd172
commit
b55c968730
@ -9,8 +9,11 @@ package gin
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@ -26,6 +29,24 @@ func (i interceptedWriter) WriteHeader(code int) {
|
||||
i.ResponseWriter.WriteHeader(code)
|
||||
}
|
||||
|
||||
func TestContextFormFileFailed17(t *testing.T) {
|
||||
if !isGo117OrGo118() {
|
||||
return
|
||||
}
|
||||
buf := new(bytes.Buffer)
|
||||
mw := multipart.NewWriter(buf)
|
||||
mw.Close()
|
||||
c, _ := CreateTestContext(httptest.NewRecorder())
|
||||
c.Request, _ = http.NewRequest("POST", "/", nil)
|
||||
c.Request.Header.Set("Content-Type", mw.FormDataContentType())
|
||||
c.engine.MaxMultipartMemory = 8 << 20
|
||||
assert.Panics(t, func() {
|
||||
f, err := c.FormFile("file")
|
||||
assert.Error(t, err)
|
||||
assert.Nil(t, f)
|
||||
})
|
||||
}
|
||||
|
||||
func TestInterceptedHeader(t *testing.T) {
|
||||
w := httptest.NewRecorder()
|
||||
c, r := CreateTestContext(w)
|
||||
@ -54,3 +75,15 @@ func TestInterceptedHeader(t *testing.T) {
|
||||
assert.Equal(t, "", w.Result().Header.Get("X-Test"))
|
||||
assert.Equal(t, "present", w.Result().Header.Get("X-Test-2"))
|
||||
}
|
||||
|
||||
func isGo117OrGo118() bool {
|
||||
version := strings.Split(runtime.Version()[2:], ".")
|
||||
if len(version) >= 2 {
|
||||
x := version[0]
|
||||
y := version[1]
|
||||
if x == "1" && (y == "17" || y == "18") {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user