MCPcopy
hub / github.com/labstack/echo / bindMultipartFiles

Function bindMultipartFiles

bind_test.go:1543–1568  ·  view source on GitHub ↗
(t *testing.T, target any, files ...testFormFile)

Source from the content-addressed store, hash-verified

1541}
1542
1543func bindMultipartFiles(t *testing.T, target any, files ...testFormFile) error {
1544 var body bytes.Buffer
1545 mw := multipart.NewWriter(&body)
1546
1547 for _, file := range files {
1548 fw, err := mw.CreateFormFile(file.Fieldname, file.Filename)
1549 assert.NoError(t, err)
1550
1551 n, err := fw.Write(file.Content)
1552 assert.NoError(t, err)
1553 assert.Equal(t, len(file.Content), n)
1554 }
1555
1556 err := mw.Close()
1557 assert.NoError(t, err)
1558
1559 req, err := http.NewRequest(http.MethodPost, "/", &body)
1560 assert.NoError(t, err)
1561 req.Header.Set("Content-Type", mw.FormDataContentType())
1562
1563 rec := httptest.NewRecorder()
1564
1565 e := New()
1566 c := e.NewContext(req, rec)
1567 return c.Bind(target)
1568}
1569
1570func assertMultipartFileHeader(t *testing.T, fh *multipart.FileHeader, file testFormFile) {
1571 assert.Equal(t, file.Filename, fh.Filename)

Callers 1

Calls 6

BindMethod · 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…