From 479ec1aad0bc763721d902c46c37f567a9c4e1c7 Mon Sep 17 00:00:00 2001 From: Tevic Date: Wed, 1 Sep 2021 12:48:43 +0800 Subject: [PATCH] fix: UnitTest for invalid proto obj --- binding/binding_test.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/binding/binding_test.go b/binding/binding_test.go index 17df7dc5..5b0ce39d 100644 --- a/binding/binding_test.go +++ b/binding/binding_test.go @@ -1339,6 +1339,13 @@ func testProtoBodyBindingFail(t *testing.T, b Binding, name, path, badPath, body err := b.Bind(req, &obj) assert.Error(t, err) + invalid_obj := FooStruct{} + req.Body = ioutil.NopCloser(strings.NewReader(`{"msg":"hello"}`)) + req.Header.Add("Content-Type", MIMEPROTOBUF) + err = b.Bind(req, &invalid_obj) + assert.Error(t, err) + assert.Equal(t, err.Error(), "obj is not ProtoMessage") + obj = protoexample.Test{} req = requestWithBody("POST", badPath, badBody) req.Header.Add("Content-Type", MIMEPROTOBUF)