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

Function testProtoBodyBinding

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

Source from the content-addressed store, hash-verified

1341}
1342
1343func testProtoBodyBinding(t *testing.T, b Binding, name, path, badPath, body, badBody string) {
1344 assert.Equal(t, name, b.Name())
1345
1346 obj := protoexample.Test{}
1347 req := requestWithBody(http.MethodPost, path, body)
1348 req.Header.Add("Content-Type", MIMEPROTOBUF)
1349 err := b.Bind(req, &obj)
1350 require.NoError(t, err)
1351 assert.Equal(t, "yes", *obj.Label)
1352
1353 obj = protoexample.Test{}
1354 req = requestWithBody(http.MethodPost, badPath, badBody)
1355 req.Header.Add("Content-Type", MIMEPROTOBUF)
1356 err = ProtoBuf.Bind(req, &obj)
1357 require.Error(t, err)
1358}
1359
1360type hook struct{}
1361

Callers 1

TestBindingProtoBufFunction · 0.85

Calls 4

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

Tested by

no test coverage detected