forked from gin-gonic/gin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix go1.17 test error (gin-gonic#2856)
(cherry picked from commit e4c026e)
- Loading branch information
Showing
3 changed files
with
64 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright 2021 Gin Core Team. All rights reserved. | ||
// Use of this source code is governed by a MIT style | ||
// license that can be found in the LICENSE file. | ||
|
||
//go:build !go1.17 | ||
// +build !go1.17 | ||
|
||
package gin | ||
|
||
import ( | ||
"bytes" | ||
"mime/multipart" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestContextFormFileFailed16(t *testing.T) { | ||
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 | ||
f, err := c.FormFile("file") | ||
assert.Error(t, err) | ||
assert.Nil(t, f) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2021 Gin Core Team. All rights reserved. | ||
// Use of this source code is governed by a MIT style | ||
// license that can be found in the LICENSE file. | ||
|
||
//go:build go1.17 | ||
// +build go1.17 | ||
|
||
package gin | ||
|
||
import ( | ||
"bytes" | ||
"mime/multipart" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestContextFormFileFailed17(t *testing.T) { | ||
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) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters