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

Function TestBindingFormFilesMultipart

binding/binding_test.go:658–678  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

656}
657
658func TestBindingFormFilesMultipart(t *testing.T) {
659 req := createFormFilesMultipartRequest(t)
660 var obj FooBarFileStruct
661 err := FormMultipart.Bind(req, &obj)
662 require.NoError(t, err)
663
664 // file from os
665 f, _ := os.Open("form.go")
666 defer f.Close()
667 fileActual, _ := io.ReadAll(f)
668
669 // file from multipart
670 mf, _ := obj.File.Open()
671 defer mf.Close()
672 fileExpect, _ := io.ReadAll(mf)
673
674 assert.Equal(t, "multipart/form-data", FormMultipart.Name())
675 assert.Equal(t, "bar", obj.Foo)
676 assert.Equal(t, "foo", obj.Bar)
677 assert.Equal(t, fileExpect, fileActual)
678}
679
680func TestBindingFormFilesMultipartFail(t *testing.T) {
681 req := createFormFilesMultipartRequestFail(t)

Callers

nothing calls this directly

Calls 5

CloseMethod · 0.80
BindMethod · 0.65
NameMethod · 0.65
OpenMethod · 0.45

Tested by

no test coverage detected