Skip to content
Myr

Fix go1.17 test error (#2856)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by thinkerou · committed by GitHub · parent 30cdbfc · Browse files · 3 files+64 added−13 removed
This commit

State

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

3 files+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.45//go:build !go1.176// +build !go1.1778package gin910import (11 "bytes"12 "mime/multipart"13 "net/http"14 "net/http/httptest"15 "testing"1617 "github.com/stretchr/testify/assert"18)1920func 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.45//go:build go1.176// +build go1.1778package gin910import (11 "bytes"12 "mime/multipart"13 "net/http"14 "net/http/httptest"15 "testing"1617 "github.com/stretchr/testify/assert"18)1920func 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}
modified:context_test.go-13 removed
85 unmodified lines
8687 assert.NoError(t, c.SaveUploadedFile(f, "test"))88}8990func TestContextFormFileFailed(t *testing.T) {91 buf := new(bytes.Buffer)92 mw := multipart.NewWriter(buf)93 mw.Close()94 c, _ := CreateTestContext(httptest.NewRecorder())95 c.Request, _ = http.NewRequest("POST", "/", nil)96 c.Request.Header.Set("Content-Type", mw.FormDataContentType())97 c.engine.MaxMultipartMemory = 8 << 2098 f, err := c.FormFile("file")99 assert.Error(t, err)100 assert.Nil(t, f)101}10290func TestContextMultipartForm(t *testing.T) {91 buf := new(bytes.Buffer)92 mw := multipart.NewWriter(buf)93 assert.NoError(t, mw.WriteField("foo", "bar"))
2046 unmodified lines