add part unit test case

This commit is contained in:
thinkerou 2018-06-10 14:43:49 +08:00
parent 41aeb74ac6
commit 9ceded8324

View File

@ -282,7 +282,7 @@ func TestBindingFormInvalidName2(t *testing.T) {
func TestBindingFormForType(t *testing.T) { func TestBindingFormForType(t *testing.T) {
testFormBindingForType(t, "POST", testFormBindingForType(t, "POST",
"/", "/", "/", "/",
"map_foo=", "bar2=1", "Map") "map_foo={\"bar\":123", "bar2=1", "Map")
testFormBindingForType(t, "POST", testFormBindingForType(t, "POST",
"/", "/", "/", "/",
@ -486,7 +486,7 @@ func createDefaultFormPostRequest() *http.Request {
} }
func createFormPostRequestFail() *http.Request { func createFormPostRequestFail() *http.Request {
req, _ := http.NewRequest("POST", "/?map_foo=getfoo", bytes.NewBufferString("map_foo=bar")) req, _ := http.NewRequest("POST", "/?map_foo=getfoo", bytes.NewBufferString("map_foo={\"bar\":123}"))
req.Header.Set("Content-Type", MIMEPOSTForm) req.Header.Set("Content-Type", MIMEPOSTForm)
return req return req
} }
@ -512,7 +512,7 @@ func createFormMultipartRequestFail() *http.Request {
defer mw.Close() defer mw.Close()
mw.SetBoundary(boundary) mw.SetBoundary(boundary)
mw.WriteField("map_foo", "bar") mw.WriteField("map_foo", "{\"bar\":123}")
req, _ := http.NewRequest("POST", "/?map_foo=getfoo", body) req, _ := http.NewRequest("POST", "/?map_foo=getfoo", body)
req.Header.Set("Content-Type", MIMEMultipartPOSTForm+"; boundary="+boundary) req.Header.Set("Content-Type", MIMEMultipartPOSTForm+"; boundary="+boundary)
return req return req
@ -541,7 +541,8 @@ func TestBindingFormPostFail(t *testing.T) {
req := createFormPostRequestFail() req := createFormPostRequestFail()
var obj FooStructForMapType var obj FooStructForMapType
err := FormPost.Bind(req, &obj) err := FormPost.Bind(req, &obj)
assert.Error(t, err) assert.Nil(t, err)
assert.Equal(t, float64(123), obj.MapFoo["bar"].(float64))
} }
func TestBindingFormMultipart(t *testing.T) { func TestBindingFormMultipart(t *testing.T) {
@ -558,7 +559,8 @@ func TestBindingFormMultipartFail(t *testing.T) {
req := createFormMultipartRequestFail() req := createFormMultipartRequestFail()
var obj FooStructForMapType var obj FooStructForMapType
err := FormMultipart.Bind(req, &obj) err := FormMultipart.Bind(req, &obj)
assert.Error(t, err) assert.Nil(t, err)
assert.Equal(t, float64(123), obj.MapFoo["bar"].(float64))
} }
func TestBindingProtoBuf(t *testing.T) { func TestBindingProtoBuf(t *testing.T) {