File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed
Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -774,6 +774,11 @@ func TestContextMultipartForm(t *testing.T) {
774774 buf := new (bytes.Buffer )
775775 mw := multipart .NewWriter (buf )
776776 mw .WriteField ("name" , "Jon Snow" )
777+ fileContent := "This is a test file"
778+ w , err := mw .CreateFormFile ("file" , "test.txt" )
779+ if assert .NoError (t , err ) {
780+ w .Write ([]byte (fileContent ))
781+ }
777782 mw .Close ()
778783 req := httptest .NewRequest (http .MethodPost , "/" , buf )
779784 req .Header .Set (HeaderContentType , mw .FormDataContentType ())
@@ -782,6 +787,13 @@ func TestContextMultipartForm(t *testing.T) {
782787 f , err := c .MultipartForm ()
783788 if assert .NoError (t , err ) {
784789 assert .NotNil (t , f )
790+
791+ files := f .File ["file" ]
792+ if assert .Len (t , files , 1 ) {
793+ file := files [0 ]
794+ assert .Equal (t , "test.txt" , file .Filename )
795+ assert .Equal (t , int64 (len (fileContent )), file .Size )
796+ }
785797 }
786798}
787799
You can’t perform that action at this time.
0 commit comments