File tree 1 file changed +12
-0
lines changed
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) {
774
774
buf := new (bytes.Buffer )
775
775
mw := multipart .NewWriter (buf )
776
776
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
+ }
777
782
mw .Close ()
778
783
req := httptest .NewRequest (http .MethodPost , "/" , buf )
779
784
req .Header .Set (HeaderContentType , mw .FormDataContentType ())
@@ -782,6 +787,13 @@ func TestContextMultipartForm(t *testing.T) {
782
787
f , err := c .MultipartForm ()
783
788
if assert .NoError (t , err ) {
784
789
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
+ }
785
797
}
786
798
}
787
799
You can’t perform that action at this time.
0 commit comments