(t *testing.T, b Binding, name, path, badPath, body, badBody string)
| 1404 | } |
| 1405 | |
| 1406 | func testProtoBodyBindingFail(t *testing.T, b Binding, name, path, badPath, body, badBody string) { |
| 1407 | assert.Equal(t, name, b.Name()) |
| 1408 | |
| 1409 | obj := protoexample.Test{} |
| 1410 | req := requestWithBody(http.MethodPost, path, body) |
| 1411 | |
| 1412 | req.Body = io.NopCloser(&hook{}) |
| 1413 | req.Header.Add("Content-Type", MIMEPROTOBUF) |
| 1414 | err := b.Bind(req, &obj) |
| 1415 | require.Error(t, err) |
| 1416 | |
| 1417 | invalidobj := FooStruct{} |
| 1418 | req.Body = io.NopCloser(strings.NewReader(`{"msg":"hello"}`)) |
| 1419 | req.Header.Add("Content-Type", MIMEPROTOBUF) |
| 1420 | err = b.Bind(req, &invalidobj) |
| 1421 | require.Error(t, err) |
| 1422 | assert.Equal(t, "obj is not ProtoMessage", err.Error()) |
| 1423 | |
| 1424 | obj = protoexample.Test{} |
| 1425 | req = requestWithBody(http.MethodPost, badPath, badBody) |
| 1426 | req.Header.Add("Content-Type", MIMEPROTOBUF) |
| 1427 | err = ProtoBuf.Bind(req, &obj) |
| 1428 | require.Error(t, err) |
| 1429 | } |
| 1430 | |
| 1431 | func requestWithBody(method, path, body string) (req *http.Request) { |
| 1432 | req, _ = http.NewRequest(method, path, bytes.NewBufferString(body)) |
no test coverage detected