save code
This commit is contained in:
parent
09c09a9621
commit
0e090ee488
43
run_test.go
43
run_test.go
@ -10,6 +10,7 @@ package validator
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"git.zhangdeman.cn/gateway/validator/define"
|
"git.zhangdeman.cn/gateway/validator/define"
|
||||||
|
"git.zhangdeman.cn/zhangdeman/consts"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
@ -139,3 +140,45 @@ func TestRunString(t *testing.T) {
|
|||||||
fmt.Println(err.Error())
|
fmt.Println(err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestRunFieldDepend 测试字段依赖关系
|
||||||
|
//
|
||||||
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
|
//
|
||||||
|
// Date : 18:40 2024/11/1
|
||||||
|
func TestRunFieldDepend(t *testing.T) {
|
||||||
|
sourceData := map[string]interface{}{
|
||||||
|
"name": "",
|
||||||
|
}
|
||||||
|
ruleListForDepend := []*define.FieldRule{
|
||||||
|
&define.FieldRule{
|
||||||
|
Path: "name",
|
||||||
|
Type: "string",
|
||||||
|
DisableRewrite: false,
|
||||||
|
DefaultValue: nil,
|
||||||
|
IsRequired: false,
|
||||||
|
AllowEmpty: false,
|
||||||
|
AllowZero: false,
|
||||||
|
AllowNil: false,
|
||||||
|
DisableAutoTrimSpace: false,
|
||||||
|
DisableAutoConvert: false,
|
||||||
|
RequiredConditionGroup: [][]define.RequiredCondition{
|
||||||
|
[]define.RequiredCondition{
|
||||||
|
define.RequiredCondition{
|
||||||
|
DependOnField: "age",
|
||||||
|
DependOnFieldType: "int",
|
||||||
|
DependOnFieldStatus: []string{consts.DataStatusIsEmpty, consts.DataStatusIsNil},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
ValueLimit: nil,
|
||||||
|
SliceConfig: nil,
|
||||||
|
MapConfig: nil,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
err := Run(sourceData, ruleListForDepend, nil)
|
||||||
|
if nil != err {
|
||||||
|
fmt.Println(err.Error())
|
||||||
|
}
|
||||||
|
assert.Error(t, err)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user