...

Source file src/github.com/gin-gonic/gin/context_1.18_test.go

Documentation: github.com/gin-gonic/gin

     1  // Copyright 2021 Gin Core Team. All rights reserved.
     2  // Use of this source code is governed by a MIT style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build !go1.19
     6  
     7  package gin
     8  
     9  import (
    10  	"bytes"
    11  	"mime/multipart"
    12  	"net/http"
    13  	"net/http/httptest"
    14  	"testing"
    15  
    16  	"github.com/stretchr/testify/assert"
    17  )
    18  
    19  func TestContextFormFileFailed18(t *testing.T) {
    20  	buf := new(bytes.Buffer)
    21  	mw := multipart.NewWriter(buf)
    22  	defer func(mw *multipart.Writer) {
    23  		err := mw.Close()
    24  		if err != nil {
    25  			assert.Error(t, err)
    26  		}
    27  	}(mw)
    28  	c, _ := CreateTestContext(httptest.NewRecorder())
    29  	c.Request, _ = http.NewRequest("POST", "/", nil)
    30  	c.Request.Header.Set("Content-Type", mw.FormDataContentType())
    31  	c.engine.MaxMultipartMemory = 8 << 20
    32  	assert.Panics(t, func() {
    33  		f, err := c.FormFile("file")
    34  		assert.Error(t, err)
    35  		assert.Nil(t, f)
    36  	})
    37  }
    38  

View as plain text