增加atring trim/convert 验证

This commit is contained in:
白茶清欢 2024-11-01 18:32:13 +08:00
parent 4c70ca6f84
commit d3be2ddb2d

View File

@ -106,20 +106,16 @@ func TestRunRequired(t *testing.T) {
} }
ruleListForDisableAutoConvert := []*define.FieldRule{ ruleListForDisableAutoConvert := []*define.FieldRule{
&define.FieldRule{ &define.FieldRule{
Path: "name", Path: "name",
Type: "string", Type: "string",
DisableRewrite: false, DisableRewrite: false,
DefaultValue: nil, DefaultValue: nil,
IsRequired: true, IsRequired: true,
AllowEmpty: false, AllowEmpty: false,
AllowZero: false, AllowZero: false,
AllowNil: false, AllowNil: false,
DisableAutoTrimSpace: false, DisableAutoTrimSpace: false,
DisableAutoConvert: true, DisableAutoConvert: true,
RequiredConditionGroup: nil,
ValueLimit: nil,
SliceConfig: nil,
MapConfig: nil,
}, },
} }
err = Run(sourceData, ruleListForDisableAutoConvert, nil) err = Run(sourceData, ruleListForDisableAutoConvert, nil)
@ -127,4 +123,49 @@ func TestRunRequired(t *testing.T) {
fmt.Println(err.Error()) fmt.Println(err.Error())
} }
assert.Error(t, err) assert.Error(t, err)
sourceData = map[string]interface{}{
"name": " ",
}
ruleListForAllowTrim := []*define.FieldRule{
&define.FieldRule{
Path: "name",
Type: "string",
DisableRewrite: false,
DefaultValue: nil,
IsRequired: true,
AllowEmpty: false,
AllowZero: false,
AllowNil: false,
DisableAutoTrimSpace: false,
DisableAutoConvert: true,
},
}
err = Run(sourceData, ruleListForAllowTrim, nil)
if nil != err {
fmt.Println(err.Error())
}
assert.Error(t, err)
sourceData = map[string]interface{}{
"name": " ",
}
ruleListForDisableTrim := []*define.FieldRule{
&define.FieldRule{
Path: "name",
Type: "string",
DisableRewrite: false,
DefaultValue: nil,
IsRequired: true,
AllowEmpty: false,
AllowZero: false,
AllowNil: false,
DisableAutoTrimSpace: true,
DisableAutoConvert: true,
},
}
err = Run(sourceData, ruleListForDisableTrim, nil)
if nil != err {
fmt.Println(err.Error())
}
} }