mirror of
https://github.com/gin-gonic/gin.git
synced 2026-11-23 11:33:37 +08:00
test(binding): check bad bodies with the binding under test
testBodyBinding and testBodyBindingFail receive the binding under test as `b`, but their second half bound the bad body with JSON.Bind. For XML, TOML, YAML and BSON this meant the validation case never ran through the binding being tested. As a result, making xmlBinding or tomlBinding ignore decode errors and skip validate() (`err != nil` -> `err == nil` in decodeXML/decodeTOML) kept the whole binding package green. With b.Bind, TestBindingXML, TestBindingXMLFail, TestBindingTOML and TestBindingTOMLFail fail on that change and pass on master.
This commit is contained in:
parent
43fe48e8a0
commit
441ee408b1
@ -1225,7 +1225,7 @@ func testBodyBinding(t *testing.T, b Binding, name, path, badPath, body, badBody
|
||||
|
||||
obj = FooStruct{}
|
||||
req = requestWithBody(http.MethodPost, badPath, badBody)
|
||||
err = JSON.Bind(req, &obj)
|
||||
err = b.Bind(req, &obj)
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
@ -1336,7 +1336,7 @@ func testBodyBindingFail(t *testing.T, b Binding, name, path, badPath, body, bad
|
||||
|
||||
obj = FooStruct{}
|
||||
req = requestWithBody(http.MethodPost, badPath, badBody)
|
||||
err = JSON.Bind(req, &obj)
|
||||
err = b.Bind(req, &obj)
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user