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

Function testBodyBinding

binding/binding_test.go:1217–1230  ·  view source on GitHub ↗
(t *testing.T, b Binding, name, path, badPath, body, badBody string)

Source from the content-addressed store, hash-verified

1215}
1216
1217func testBodyBinding(t *testing.T, b Binding, name, path, badPath, body, badBody string) {
1218 assert.Equal(t, name, b.Name())
1219
1220 obj := FooStruct{}
1221 req := requestWithBody(http.MethodPost, path, body)
1222 err := b.Bind(req, &obj)
1223 require.NoError(t, err)
1224 assert.Equal(t, "bar", obj.Foo)
1225
1226 obj = FooStruct{}
1227 req = requestWithBody(http.MethodPost, badPath, badBody)
1228 err = JSON.Bind(req, &obj)
1229 require.Error(t, err)
1230}
1231
1232func testBodyBindingSlice(t *testing.T, b Binding, name, path, badPath, body, badBody string) {
1233 assert.Equal(t, name, b.Name())

Callers 5

TestBindingJSONFunction · 0.85
TestBindingXMLFunction · 0.85
TestBindingTOMLFunction · 0.85
TestBindingYAMLFunction · 0.85
TestBindingBSONFunction · 0.85

Calls 4

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

Tested by

no test coverage detected