mirror of https://github.com/gin-gonic/gin.git
add test function
This commit is contained in:
parent
15e9387ca0
commit
36f6c493d4
|
@ -1177,6 +1177,20 @@ func testBodyBindingFail(t *testing.T, b Binding, name, path, badPath, body, bad
|
|||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
type Identifier struct {
|
||||
Assigner *Reference `json:"assigner,omitempty"`
|
||||
}
|
||||
|
||||
type Reference struct {
|
||||
Identifier *Identifier `json:"identifier,omitempty"`
|
||||
}
|
||||
|
||||
func TestLoopReference(t *testing.T) {
|
||||
r := Reference{}
|
||||
err := mapForm(&r, map[string][]string{})
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func testProtoBodyBinding(t *testing.T, b Binding, name, path, badPath, body, badBody string) {
|
||||
assert.Equal(t, name, b.Name())
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ import (
|
|||
var LimitMappingCallNumber = 10000
|
||||
|
||||
var errUnknownType = errors.New("Unknown type")
|
||||
var ErrMaybeCircularReference = errors.New("Maybe entering a circular reference")
|
||||
|
||||
func mapUri(ptr interface{}, m map[string][]string) error {
|
||||
return mapFormByTag(ptr, m, "uri")
|
||||
|
@ -73,7 +74,7 @@ func mapping(value reflect.Value, field reflect.StructField, setter setter, tag
|
|||
}
|
||||
|
||||
if callNumber > LimitMappingCallNumber {
|
||||
return false, errors.New("Maybe entering a circular reference")
|
||||
return false, ErrMaybeCircularReference
|
||||
}
|
||||
|
||||
if vKind != reflect.Struct || !field.Anonymous {
|
||||
|
|
|
@ -52,7 +52,7 @@ func TestMappingBaseTypes(t *testing.T) {
|
|||
|
||||
field := val.Elem().Type().Field(0)
|
||||
|
||||
_, err := mapping(val, emptyField, formSource{field.Name: {tt.form}}, "form")
|
||||
_, err := mapping(val, emptyField, formSource{field.Name: {tt.form}}, "form", 0)
|
||||
assert.NoError(t, err, testName)
|
||||
|
||||
actual := val.Elem().Field(0).Interface()
|
||||
|
|
Loading…
Reference in New Issue