diff --git a/run_test.go b/run_test.go index 66d8056..96f16ca 100644 --- a/run_test.go +++ b/run_test.go @@ -10,6 +10,7 @@ package validator import ( "fmt" "git.zhangdeman.cn/gateway/validator/define" + "git.zhangdeman.cn/zhangdeman/consts" "github.com/stretchr/testify/assert" "testing" ) @@ -139,3 +140,45 @@ func TestRunString(t *testing.T) { 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) +}