Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+64 added−13 removed
other:+64 added−13 removed
Provenance
Commit
e4c026e
Tree
0ffa907
Author
thinkerou <thinkerou@gmail.com>
Committer
GitHub <noreply@github.com>
Parent
30cdbfc
3 files changed+64 added−13 removed
added:context_1.16_test.go+31 added
1+// Copyright 2021 Gin Core Team. All rights reserved.2+// Use of this source code is governed by a MIT style3+// license that can be found in the LICENSE file.4+5+//go:build !go1.176+// +build !go1.177+8+package gin9+10+import (11+ "bytes"12+ "mime/multipart"13+ "net/http"14+ "net/http/httptest"15+ "testing"16+17+ "github.com/stretchr/testify/assert"18+)19+20+func TestContextFormFileFailed16(t *testing.T) {21+ buf := new(bytes.Buffer)22+ mw := multipart.NewWriter(buf)23+ mw.Close()24+ c, _ := CreateTestContext(httptest.NewRecorder())25+ c.Request, _ = http.NewRequest("POST", "/", nil)26+ c.Request.Header.Set("Content-Type", mw.FormDataContentType())27+ c.engine.MaxMultipartMemory = 8 << 2028+ f, err := c.FormFile("file")29+ assert.Error(t, err)30+ assert.Nil(t, f)31+}
added:context_1.17_test.go+33 added
1+// Copyright 2021 Gin Core Team. All rights reserved.2+// Use of this source code is governed by a MIT style3+// license that can be found in the LICENSE file.4+5+//go:build go1.176+// +build go1.177+8+package gin9+10+import (11+ "bytes"12+ "mime/multipart"13+ "net/http"14+ "net/http/httptest"15+ "testing"16+17+ "github.com/stretchr/testify/assert"18+)19+20+func TestContextFormFileFailed17(t *testing.T) {21+ buf := new(bytes.Buffer)22+ mw := multipart.NewWriter(buf)23+ mw.Close()24+ c, _ := CreateTestContext(httptest.NewRecorder())25+ c.Request, _ = http.NewRequest("POST", "/", nil)26+ c.Request.Header.Set("Content-Type", mw.FormDataContentType())27+ c.engine.MaxMultipartMemory = 8 << 2028+ assert.Panics(t, func() {29+ f, err := c.FormFile("file")30+ assert.Error(t, err)31+ assert.Nil(t, f)32+ })33+}