MCPcopy
hub / github.com/gin-gonic/gin / TestContextMultipartForm

Function TestContextMultipartForm

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

Source from the content-addressed store, hash-verified

181}
182
183func TestContextMultipartForm(t *testing.T) {
184 buf := new(bytes.Buffer)
185 mw := multipart.NewWriter(buf)
186 require.NoError(t, mw.WriteField("foo", "bar"))
187 w, err := mw.CreateFormFile("file", "test")
188 require.NoError(t, err)
189 _, err = w.Write([]byte("test"))
190 require.NoError(t, err)
191 mw.Close()
192 c, _ := CreateTestContext(httptest.NewRecorder())
193 c.Request, _ = http.NewRequest(http.MethodPost, "/", buf)
194 c.Request.Header.Set("Content-Type", mw.FormDataContentType())
195 f, err := c.MultipartForm()
196 require.NoError(t, err)
197 assert.NotNil(t, f)
198
199 require.NoError(t, c.SaveUploadedFile(f.File["file"][0], "test"))
200}
201
202func TestSaveUploadedOpenFailed(t *testing.T) {
203 buf := new(bytes.Buffer)

Callers

nothing calls this directly

Calls 6

CreateTestContextFunction · 0.85
CloseMethod · 0.80
SetMethod · 0.80
MultipartFormMethod · 0.80
SaveUploadedFileMethod · 0.80
WriteMethod · 0.45

Tested by

no test coverage detected