From a2a2dfd1720aeaa32a80d1dee928b1ffa6ed0183 Mon Sep 17 00:00:00 2001 From: mstmdev Date: Wed, 17 Aug 2022 11:57:10 +0800 Subject: [PATCH] Remove !go1.19 and update tests --- context_1.17_test.go | 20 ++------------------ context_1.19_test.go | 39 --------------------------------------- 2 files changed, 2 insertions(+), 57 deletions(-) diff --git a/context_1.17_test.go b/context_1.17_test.go index 4c2047e8..f9e2148e 100644 --- a/context_1.17_test.go +++ b/context_1.17_test.go @@ -2,14 +2,13 @@ // Use of this source code is governed by a MIT style // license that can be found in the LICENSE file. -//go:build go1.17 && !go1.19 -// +build go1.17,!go1.19 +//go:build go1.17 +// +build go1.17 package gin import ( "bytes" - "mime/multipart" "net/http" "net/http/httptest" "testing" @@ -27,21 +26,6 @@ func (i interceptedWriter) WriteHeader(code int) { i.ResponseWriter.WriteHeader(code) } -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) - }) -} - func TestInterceptedHeader(t *testing.T) { w := httptest.NewRecorder() c, r := CreateTestContext(w) diff --git a/context_1.19_test.go b/context_1.19_test.go index b70ef557..4b34ea24 100644 --- a/context_1.19_test.go +++ b/context_1.19_test.go @@ -17,16 +17,6 @@ import ( "github.com/stretchr/testify/assert" ) -type interceptedWriter struct { - ResponseWriter - b *bytes.Buffer -} - -func (i interceptedWriter) WriteHeader(code int) { - i.Header().Del("X-Test") - i.ResponseWriter.WriteHeader(code) -} - func TestContextFormFileFailed19(t *testing.T) { buf := new(bytes.Buffer) mw := multipart.NewWriter(buf) @@ -39,32 +29,3 @@ func TestContextFormFileFailed19(t *testing.T) { assert.Error(t, err) assert.Nil(t, f) } - -func TestInterceptedHeader(t *testing.T) { - w := httptest.NewRecorder() - c, r := CreateTestContext(w) - - r.Use(func(c *Context) { - i := interceptedWriter{ - ResponseWriter: c.Writer, - b: bytes.NewBuffer(nil), - } - c.Writer = i - c.Next() - c.Header("X-Test", "overridden") - c.Writer = i.ResponseWriter - }) - r.GET("/", func(c *Context) { - c.Header("X-Test", "original") - c.Header("X-Test-2", "present") - c.String(http.StatusOK, "hello world") - }) - c.Request = httptest.NewRequest("GET", "/", nil) - r.HandleContext(c) - // Result() has headers frozen when WriteHeaderNow() has been called - // Compared to this time, this is when the response headers will be flushed - // As response is flushed on c.String, the Header cannot be set by the first - // middleware. Assert this - assert.Equal(t, "", w.Result().Header.Get("X-Test")) - assert.Equal(t, "present", w.Result().Header.Get("X-Test-2")) -}