增加atring trim/convert 验证

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

View File

@ -116,10 +116,6 @@ func TestRunRequired(t *testing.T) {
AllowNil: false,
DisableAutoTrimSpace: false,
DisableAutoConvert: true,
RequiredConditionGroup: nil,
ValueLimit: nil,
SliceConfig: nil,
MapConfig: nil,
},
}
err = Run(sourceData, ruleListForDisableAutoConvert, nil)
@ -127,4 +123,49 @@ func TestRunRequired(t *testing.T) {
fmt.Println(err.Error())
}
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())
}
}