MCPcopy Index your code
hub / github.com/labstack/echo / TestContextMultipartForm

Function TestContextMultipartForm

context_test.go:963–989  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

961}
962
963func TestContextMultipartForm(t *testing.T) {
964 e := New()
965 buf := new(bytes.Buffer)
966 mw := multipart.NewWriter(buf)
967 mw.WriteField("name", "Jon Snow")
968 fileContent := "This is a test file"
969 w, err := mw.CreateFormFile("file", "test.txt")
970 if assert.NoError(t, err) {
971 w.Write([]byte(fileContent))
972 }
973 mw.Close()
974 req := httptest.NewRequest(http.MethodPost, "/", buf)
975 req.Header.Set(HeaderContentType, mw.FormDataContentType())
976 rec := httptest.NewRecorder()
977 c := e.NewContext(req, rec)
978 f, err := c.MultipartForm()
979 if assert.NoError(t, err) {
980 assert.NotNil(t, f)
981
982 files := f.File["file"]
983 if assert.Len(t, files, 1) {
984 file := files[0]
985 assert.Equal(t, "test.txt", file.Filename)
986 assert.Equal(t, int64(len(fileContent)), file.Size)
987 }
988 }
989}
990
991func TestContextRedirect(t *testing.T) {
992 e := New()

Callers

nothing calls this directly

Calls 6

MultipartFormMethod · 0.95
NewFunction · 0.85
SetMethod · 0.80
NewContextMethod · 0.80
WriteMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…