mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-23 17:20:24 +08:00
chore: coding style (#3413)
This commit is contained in:
parent
b9c0c0f8b5
commit
0c6eaeda9f
@ -618,7 +618,7 @@ func (u *Unmarshaler) processFieldPrimitiveWithJSONNumber(fieldType reflect.Type
|
|||||||
|
|
||||||
target.SetFloat(fValue)
|
target.SetFloat(fValue)
|
||||||
default:
|
default:
|
||||||
return newTypeMismatchErrorWithHint(fullName, value.Type().String(), typeKind.String())
|
return newTypeMismatchErrorWithHint(fullName, typeKind.String(), value.Type().String())
|
||||||
}
|
}
|
||||||
|
|
||||||
SetValue(fieldType, value, target)
|
SetValue(fieldType, value, target)
|
||||||
@ -1054,8 +1054,9 @@ func newTypeMismatchError(name string) error {
|
|||||||
return fmt.Errorf("type mismatch for field %q", name)
|
return fmt.Errorf("type mismatch for field %q", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTypeMismatchErrorWithHint(name, errorType, rightType string) error {
|
func newTypeMismatchErrorWithHint(name, expectType, actualType string) error {
|
||||||
return fmt.Errorf("type mismatch for field %q, expected %q, got %q", name, rightType, errorType)
|
return fmt.Errorf("type mismatch for field %q, expect %q, actual %q",
|
||||||
|
name, expectType, actualType)
|
||||||
}
|
}
|
||||||
|
|
||||||
func readKeys(key string) []string {
|
func readKeys(key string) []string {
|
||||||
|
@ -4991,10 +4991,12 @@ func TestUnmarshalerProcessFieldPrimitiveWithJSONNumber(t *testing.T) {
|
|||||||
value := reflect.ValueOf(&realValue) // pass a pointer to the value
|
value := reflect.ValueOf(&realValue) // pass a pointer to the value
|
||||||
v := json.Number(expectValue)
|
v := json.Number(expectValue)
|
||||||
m := NewUnmarshaler("field")
|
m := NewUnmarshaler("field")
|
||||||
err := m.processFieldPrimitiveWithJSONNumber(fieldType, value.Elem(), v, &fieldOptionsWithContext{}, "field")
|
err := m.processFieldPrimitiveWithJSONNumber(fieldType, value.Elem(), v,
|
||||||
|
&fieldOptionsWithContext{}, "field")
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
assert.Equal(t, "type mismatch for field \"field\", expected \"string\", got \"int\"", err.Error())
|
assert.Equal(t, `type mismatch for field "field", expect "string", actual "int"`, err.Error())
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("right type", func(t *testing.T) {
|
t.Run("right type", func(t *testing.T) {
|
||||||
expectValue := int64(1)
|
expectValue := int64(1)
|
||||||
realValue := int64(1)
|
realValue := int64(1)
|
||||||
@ -5002,10 +5004,10 @@ func TestUnmarshalerProcessFieldPrimitiveWithJSONNumber(t *testing.T) {
|
|||||||
value := reflect.ValueOf(&realValue) // pass a pointer to the value
|
value := reflect.ValueOf(&realValue) // pass a pointer to the value
|
||||||
v := json.Number(strconv.FormatInt(expectValue, 10))
|
v := json.Number(strconv.FormatInt(expectValue, 10))
|
||||||
m := NewUnmarshaler("field")
|
m := NewUnmarshaler("field")
|
||||||
err := m.processFieldPrimitiveWithJSONNumber(fieldType, value.Elem(), v, &fieldOptionsWithContext{}, "field")
|
err := m.processFieldPrimitiveWithJSONNumber(fieldType, value.Elem(), v,
|
||||||
|
&fieldOptionsWithContext{}, "field")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetValueWithChainedKeys(t *testing.T) {
|
func TestGetValueWithChainedKeys(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user