Skip to content
Myr

chore(go): Add support go 1.19 (#3272)

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

authored by mstmdev · committed by GitHub · parent fa58bff · Browse files · 3 files+49 added−1 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+49 added−1 removed

  • other:+49 added−1 removed

3 files+49 added−1 removed

modified:.github/workflows/gin.yml+1 added-1 removed
modified:context_1.17_test.go+17 added
10 unmodified lines
11 "bytes"12 "mime/multipart"13 "net/http"14 "net/http/httptest"15 "runtime"16 "strings"17 "testing"1819 "github.com/stretchr/testify/assert"20)
8 unmodified lines
29 i.ResponseWriter.WriteHeader(code)30}3132func TestContextFormFileFailed17(t *testing.T) {33 if !isGo117OrGo118() {34 return35 }36 buf := new(bytes.Buffer)37 mw := multipart.NewWriter(buf)38 defer func(mw *multipart.Writer) {39 err := mw.Close()
39 unmodified lines
79 // middleware. Assert this80 assert.Equal(t, "", w.Result().Header.Get("X-Test"))81 assert.Equal(t, "present", w.Result().Header.Get("X-Test-2"))82}8384func isGo117OrGo118() bool {85 version := strings.Split(runtime.Version()[2:], ".")86 if len(version) >= 2 {87 x := version[0]88 y := version[1]89 if x == "1" && (y == "17" || y == "18") {90 return true91 }92 }93 return false94}
added:context_1.19_test.go+31 added
1// Copyright 2022 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.196// +build go1.1978package gin910import (11 "bytes"12 "mime/multipart"13 "net/http"14 "net/http/httptest"15 "testing"1617 "github.com/stretchr/testify/assert"18)1920func TestContextFormFileFailed19(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}