fix bug, return err when failed binding bool (#1350)
* fix bug, return err when failed binding bool * add test, return err when failed binding bool
This commit is contained in:
		| @ -91,6 +91,10 @@ type FooStructForSliceMapType struct { | ||||
| 	SliceMapFoo []map[string]interface{} `form:"slice_map_foo"` | ||||
| } | ||||
|  | ||||
| type FooStructForBoolType struct { | ||||
| 	BoolFoo bool `form:"bool_foo"` | ||||
| } | ||||
|  | ||||
| type FooBarStructForIntType struct { | ||||
| 	IntFoo int `form:"int_foo"` | ||||
| 	IntBar int `form:"int_bar" binding:"required"` | ||||
| @ -449,6 +453,12 @@ func TestBindingQueryFail2(t *testing.T) { | ||||
| 		"map_foo=unused", "") | ||||
| } | ||||
|  | ||||
| func TestBindingQueryBoolFail(t *testing.T) { | ||||
| 	testQueryBindingBoolFail(t, "GET", | ||||
| 		"/?bool_foo=fasl", "/?bar2=foo", | ||||
| 		"bool_foo=unused", "") | ||||
| } | ||||
|  | ||||
| func TestBindingXML(t *testing.T) { | ||||
| 	testBodyBinding(t, | ||||
| 		XML, "xml", | ||||
| @ -1063,6 +1073,19 @@ func testQueryBindingFail(t *testing.T, method, path, badPath, body, badBody str | ||||
| 	assert.Error(t, err) | ||||
| } | ||||
|  | ||||
| func testQueryBindingBoolFail(t *testing.T, method, path, badPath, body, badBody string) { | ||||
| 	b := Query | ||||
| 	assert.Equal(t, "query", b.Name()) | ||||
|  | ||||
| 	obj := FooStructForBoolType{} | ||||
| 	req := requestWithBody(method, path, body) | ||||
| 	if method == "POST" { | ||||
| 		req.Header.Add("Content-Type", MIMEPOSTForm) | ||||
| 	} | ||||
| 	err := b.Bind(req, &obj) | ||||
| 	assert.Error(t, err) | ||||
| } | ||||
|  | ||||
| func testBodyBinding(t *testing.T, b Binding, name, path, badPath, body, badBody string) { | ||||
| 	assert.Equal(t, name, b.Name()) | ||||
|  | ||||
|  | ||||
| @ -161,7 +161,7 @@ func setBoolField(val string, field reflect.Value) error { | ||||
| 	if err == nil { | ||||
| 		field.SetBool(boolVal) | ||||
| 	} | ||||
| 	return nil | ||||
| 	return err | ||||
| } | ||||
|  | ||||
| func setFloatField(val string, bitSize int, field reflect.Value) error { | ||||
|  | ||||
		Reference in New Issue
	
	Block a user