Skip to content

Commit

Permalink
chore(go): Add support go 1.19 (#3272)
Browse files Browse the repository at this point in the history
  • Loading branch information
mstmdev committed Oct 16, 2022
1 parent fa58bff commit 4c64f1c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/gin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
go: [1.16, 1.17, 1.18]
go: [1.16, 1.17, 1.18, 1.19]
test-tags: ['', '-tags nomsgpack', '-tags "sonic avx"', '-tags go_json']
include:
- os: ubuntu-latest
Expand Down
17 changes: 17 additions & 0 deletions context_1.17_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"mime/multipart"
"net/http"
"net/http/httptest"
"runtime"
"strings"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -28,6 +30,9 @@ func (i interceptedWriter) WriteHeader(code int) {
}

func TestContextFormFileFailed17(t *testing.T) {
if !isGo117OrGo118() {
return
}
buf := new(bytes.Buffer)
mw := multipart.NewWriter(buf)
defer func(mw *multipart.Writer) {
Expand Down Expand Up @@ -75,3 +80,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
}
31 changes: 31 additions & 0 deletions context_1.19_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2022 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.19
// +build go1.19

package gin

import (
"bytes"
"mime/multipart"
"net/http"
"net/http/httptest"
"testing"

"github.com/stretchr/testify/assert"
)

func TestContextFormFileFailed19(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)
}

0 comments on commit 4c64f1c

Please sign in to comment.