| 110 | } |
| 111 | |
| 112 | func TestToContext_MultipartForm(t *testing.T) { |
| 113 | testConf := ContextConfig{ |
| 114 | MultipartForm: &MultipartForm{ |
| 115 | Fields: map[string]string{ |
| 116 | "key": "value", |
| 117 | }, |
| 118 | Files: []MultipartFormFile{ |
| 119 | { |
| 120 | Fieldname: "file", |
| 121 | Filename: "test.json", |
| 122 | Content: LoadBytes(t, "testdata/test.json"), |
| 123 | }, |
| 124 | }, |
| 125 | }, |
| 126 | } |
| 127 | c := testConf.ToContext(t) |
| 128 | |
| 129 | assert.Equal(t, "value", c.FormValue("key")) |
| 130 | assert.Equal(t, http.MethodPost, c.Request().Method) |
| 131 | assert.Equal(t, true, strings.HasPrefix(c.Request().Header.Get(echo.HeaderContentType), "multipart/form-data; boundary=")) |
| 132 | |
| 133 | fv, err := c.FormFile("file") |
| 134 | if err != nil { |
| 135 | t.Fatal(err) |
| 136 | } |
| 137 | assert.Equal(t, "test.json", fv.Filename) |
| 138 | assert.Equal(t, int64(23), fv.Size) |
| 139 | } |
| 140 | |
| 141 | func TestToContext_JSONBody(t *testing.T) { |
| 142 | testConf := ContextConfig{ |