mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-24 02:32:17 +08:00
add test cases for form
This commit is contained in:
parent
dc56b1a1bb
commit
87d292482f
@ -57,6 +57,12 @@ type InvalidNameType struct {
|
||||
TestName string `invalid_name:"test_name"`
|
||||
}
|
||||
|
||||
type InvalidNameMapType struct {
|
||||
TestName struct {
|
||||
MapFoo map[string]interface{} `form:"map_foo"`
|
||||
}
|
||||
}
|
||||
|
||||
type FooStructForSliceType struct {
|
||||
SliceFoo []int `form:"slice_foo"`
|
||||
}
|
||||
@ -223,6 +229,12 @@ func TestBindingFormInvalidName(t *testing.T) {
|
||||
"test_name=bar", "bar2=foo")
|
||||
}
|
||||
|
||||
func TestBindingFormInvalidName2(t *testing.T) {
|
||||
testFormBindingInvalidName2(t, "POST",
|
||||
"/", "/",
|
||||
"map_foo=bar", "bar2=foo")
|
||||
}
|
||||
|
||||
func TestBindingFormForType(t *testing.T) {
|
||||
testFormBindingForType(t, "POST",
|
||||
"/", "/",
|
||||
@ -649,6 +661,24 @@ func testFormBindingInvalidName(t *testing.T, method, path, badPath, body, badBo
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func testFormBindingInvalidName2(t *testing.T, method, path, badPath, body, badBody string) {
|
||||
b := Form
|
||||
assert.Equal(t, b.Name(), "form")
|
||||
|
||||
obj := InvalidNameMapType{}
|
||||
req := requestWithBody(method, path, body)
|
||||
if method == "POST" {
|
||||
req.Header.Add("Content-Type", MIMEPOSTForm)
|
||||
}
|
||||
err := b.Bind(req, &obj)
|
||||
assert.Error(t, err)
|
||||
|
||||
obj = InvalidNameMapType{}
|
||||
req = requestWithBody(method, badPath, badBody)
|
||||
err = JSON.Bind(req, &obj)
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func testFormBindingForType(t *testing.T, method, path, badPath, body, badBody string, typ string) {
|
||||
b := Form
|
||||
assert.Equal(t, b.Name(), "form")
|
||||
|
Loading…
x
Reference in New Issue
Block a user