* fix: #2672 * chore: fix more cases * chore: update deps * chore: update deps * chore: refactor * chore: refactor * chore: refactor
This commit is contained in:
@@ -3563,6 +3563,71 @@ func TestGoogleUUID(t *testing.T) {
|
||||
assert.Equal(t, "6ba7b810-9dad-11d1-80b4-00c04fd430c2", val.Uidp.String())
|
||||
}
|
||||
|
||||
func TestUnmarshalJsonReaderWithTypeMismatchBool(t *testing.T) {
|
||||
var req struct {
|
||||
Params map[string]bool `json:"params"`
|
||||
}
|
||||
body := `{"params":{"a":"123"}}`
|
||||
assert.Equal(t, errTypeMismatch, UnmarshalJsonReader(strings.NewReader(body), &req))
|
||||
}
|
||||
|
||||
func TestUnmarshalJsonReaderWithTypeMismatchString(t *testing.T) {
|
||||
var req struct {
|
||||
Params map[string]string `json:"params"`
|
||||
}
|
||||
body := `{"params":{"a":{"a":123}}}`
|
||||
assert.Equal(t, errTypeMismatch, UnmarshalJsonReader(strings.NewReader(body), &req))
|
||||
}
|
||||
|
||||
func TestUnmarshalJsonReaderWithMismatchType(t *testing.T) {
|
||||
type Req struct {
|
||||
Params map[string]string `json:"params"`
|
||||
}
|
||||
|
||||
var req Req
|
||||
body := `{"params":{"a":{"a":123}}}`
|
||||
assert.Equal(t, errTypeMismatch, UnmarshalJsonReader(strings.NewReader(body), &req))
|
||||
}
|
||||
|
||||
func TestUnmarshalJsonReaderWithMismatchTypeBool(t *testing.T) {
|
||||
type Req struct {
|
||||
Params map[string]bool `json:"params"`
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
}{
|
||||
{
|
||||
name: "int",
|
||||
input: `{"params":{"a":123}}`,
|
||||
},
|
||||
{
|
||||
name: "int",
|
||||
input: `{"params":{"a":"123"}}`,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
test := test
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
var req Req
|
||||
assert.Equal(t, errTypeMismatch, UnmarshalJsonReader(strings.NewReader(test.input), &req))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnmarshalJsonReaderWithMismatchTypeBoolMap(t *testing.T) {
|
||||
var req struct {
|
||||
Params map[string]string `json:"params"`
|
||||
}
|
||||
assert.Equal(t, errTypeMismatch, UnmarshalJsonMap(map[string]interface{}{
|
||||
"params": map[string]interface{}{
|
||||
"a": true,
|
||||
},
|
||||
}, &req))
|
||||
}
|
||||
|
||||
func BenchmarkDefaultValue(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
var a struct {
|
||||
|
||||
Reference in New Issue
Block a user