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

Function testFormBindingDefaultValue

binding/binding_test.go:894–912  ·  view source on GitHub ↗
(t *testing.T, method, path, badPath, body, badBody string)

Source from the content-addressed store, hash-verified

892}
893
894func testFormBindingDefaultValue(t *testing.T, method, path, badPath, body, badBody string) {
895 b := Form
896 assert.Equal(t, "form", b.Name())
897
898 obj := FooDefaultBarStruct{}
899 req := requestWithBody(method, path, body)
900 if method == http.MethodPost {
901 req.Header.Add("Content-Type", MIMEPOSTForm)
902 }
903 err := b.Bind(req, &obj)
904 require.NoError(t, err)
905 assert.Equal(t, "bar", obj.Foo)
906 assert.Equal(t, "hello", obj.Bar)
907
908 obj = FooDefaultBarStruct{}
909 req = requestWithBody(method, badPath, badBody)
910 err = JSON.Bind(req, &obj)
911 require.Error(t, err)
912}
913
914func TestFormBindingFail(t *testing.T) {
915 b := Form

Callers 2

Calls 4

requestWithBodyFunction · 0.85
NameMethod · 0.65
BindMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected