mirror of
https://github.com/labstack/echo.git
synced 2024-12-24 20:14:31 +02:00
improve MultipartForm test
This commit is contained in:
parent
d20a6257aa
commit
ab87b63640
@ -774,6 +774,11 @@ func TestContextMultipartForm(t *testing.T) {
|
|||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
mw := multipart.NewWriter(buf)
|
mw := multipart.NewWriter(buf)
|
||||||
mw.WriteField("name", "Jon Snow")
|
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()
|
mw.Close()
|
||||||
req := httptest.NewRequest(http.MethodPost, "/", buf)
|
req := httptest.NewRequest(http.MethodPost, "/", buf)
|
||||||
req.Header.Set(HeaderContentType, mw.FormDataContentType())
|
req.Header.Set(HeaderContentType, mw.FormDataContentType())
|
||||||
@ -782,6 +787,13 @@ func TestContextMultipartForm(t *testing.T) {
|
|||||||
f, err := c.MultipartForm()
|
f, err := c.MultipartForm()
|
||||||
if assert.NoError(t, err) {
|
if assert.NoError(t, err) {
|
||||||
assert.NotNil(t, f)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user