From 0e090ee488f47622e877db5bdca140dd6dd2b285 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Fri, 1 Nov 2024 18:45:03 +0800 Subject: [PATCH] save code --- run_test.go | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) 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) +}