Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into bind-multipart-form…
Browse files Browse the repository at this point in the history
…-data
  • Loading branch information
martinyonatann committed Oct 10, 2024
2 parents 66dfee3 + 42a7470 commit 2d7acbf
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,11 @@ func TestContextMultipartForm(t *testing.T) {
buf := new(bytes.Buffer)
mw := multipart.NewWriter(buf)
mw.WriteField("name", "Jon Snow")
fileContent := "This is a test file"
w, err := mw.CreateFormFile("file", "test.txt")
if assert.NoError(t, err) {
w.Write([]byte(fileContent))
}
mw.Close()
req := httptest.NewRequest(http.MethodPost, "/", buf)
req.Header.Set(HeaderContentType, mw.FormDataContentType())
Expand All @@ -782,6 +787,13 @@ func TestContextMultipartForm(t *testing.T) {
f, err := c.MultipartForm()
if assert.NoError(t, err) {
assert.NotNil(t, f)

files := f.File["file"]
if assert.Len(t, files, 1) {
file := files[0]
assert.Equal(t, "test.txt", file.Filename)
assert.Equal(t, int64(len(fileContent)), file.Size)
}
}
}

Expand Down

0 comments on commit 2d7acbf

Please sign in to comment.