...

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

Documentation: github.com/gin-gonic/gin

     1  // Copyright 2022 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 TestContextFormFileFailed19(t *testing.T) {
    20  	buf := new(bytes.Buffer)
    21  	mw := multipart.NewWriter(buf)
    22  	mw.Close()
    23  	c, _ := CreateTestContext(httptest.NewRecorder())
    24  	c.Request, _ = http.NewRequest("POST", "/", nil)
    25  	c.Request.Header.Set("Content-Type", mw.FormDataContentType())
    26  	c.engine.MaxMultipartMemory = 8 << 20
    27  	f, err := c.FormFile("file")
    28  	assert.Error(t, err)
    29  	assert.Nil(t, f)
    30  }
    31  

View as plain text