|
|
|
@ -8620,14 +8620,21 @@ func TestEndsWithValidation(t *testing.T) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestRequiredWith(t *testing.T) { |
|
|
|
|
|
|
|
|
|
fieldVal := "test" |
|
|
|
|
test := struct { |
|
|
|
|
Field1 *string `validate:"omitempty" json:"field_1"` |
|
|
|
|
Field2 []string `validate:"omitempty" json:"field_2"` |
|
|
|
|
Field3 string `validate:"required_with=Field1 Field2" json:"field_3"` |
|
|
|
|
FieldE string `validate:"omitempty" json:"field_e"` |
|
|
|
|
FieldER string `validate:"required_with=FieldE" json:"field_er"` |
|
|
|
|
Field1 string `validate:"omitempty" json:"field_1"` |
|
|
|
|
Field2 *string `validate:"required_with=Field1" json:"field_2"` |
|
|
|
|
Field3 map[string]string `validate:"required_with=Field2" json:"field_3"` |
|
|
|
|
Field4 interface{} `validate:"required_with=Field3" json:"field_4"` |
|
|
|
|
Field5 string `validate:"required_with=Field3" json:"field_5"` |
|
|
|
|
}{ |
|
|
|
|
Field2: []string{"test_field2"}, |
|
|
|
|
Field3: "test_field3", |
|
|
|
|
Field1: "test_field1", |
|
|
|
|
Field2: &fieldVal, |
|
|
|
|
Field3: map[string]string{"key": "val"}, |
|
|
|
|
Field4: "test", |
|
|
|
|
Field5: "test", |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
validate := New() |
|
|
|
@ -8641,14 +8648,21 @@ func TestRequiredWith(t *testing.T) { |
|
|
|
|
|
|
|
|
|
func TestRequiredWithAll(t *testing.T) { |
|
|
|
|
|
|
|
|
|
fieldVal := "test" |
|
|
|
|
test := struct { |
|
|
|
|
FieldE string `validate:"omitempty" json:"field_e"` |
|
|
|
|
FieldER string `validate:"required_with_all=FieldE" json:"field_er"` |
|
|
|
|
Field1 string `validate:"omitempty" json:"field_1"` |
|
|
|
|
Field2 []string `validate:"omitempty" json:"field_2"` |
|
|
|
|
Field3 string `validate:"required_with_all=Field1 Field2" json:"field_3"` |
|
|
|
|
Field2 *string `validate:"required_with_all=Field1" json:"field_2"` |
|
|
|
|
Field3 map[string]string `validate:"required_with_all=Field2" json:"field_3"` |
|
|
|
|
Field4 interface{} `validate:"required_with_all=Field3" json:"field_4"` |
|
|
|
|
Field5 string `validate:"required_with_all=Field3" json:"field_5"` |
|
|
|
|
}{ |
|
|
|
|
Field1: "test_field1", |
|
|
|
|
Field2: []string{"test_field2"}, |
|
|
|
|
Field3: "test_field3", |
|
|
|
|
Field2: &fieldVal, |
|
|
|
|
Field3: map[string]string{"key": "val"}, |
|
|
|
|
Field4: "test", |
|
|
|
|
Field5: "test", |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
validate := New() |
|
|
|
@ -8662,12 +8676,18 @@ func TestRequiredWithAll(t *testing.T) { |
|
|
|
|
|
|
|
|
|
func TestRequiredWithout(t *testing.T) { |
|
|
|
|
|
|
|
|
|
fieldVal := "test" |
|
|
|
|
test := struct { |
|
|
|
|
Field1 *string `validate:"omitempty" json:"field_1"` |
|
|
|
|
Field2 []string `validate:"omitempty" json:"field_2"` |
|
|
|
|
Field3 string `validate:"required_without=Field1 Field2" json:"field_3"` |
|
|
|
|
Field1 string `validate:"omitempty" json:"field_1"` |
|
|
|
|
Field2 *string `validate:"required_without=Field1" json:"field_2"` |
|
|
|
|
Field3 map[string]string `validate:"required_without=Field2" json:"field_3"` |
|
|
|
|
Field4 interface{} `validate:"required_without=Field3" json:"field_4"` |
|
|
|
|
Field5 string `validate:"required_without=Field3" json:"field_5"` |
|
|
|
|
}{ |
|
|
|
|
Field3: "test_field3", |
|
|
|
|
Field2: &fieldVal, |
|
|
|
|
Field3: map[string]string{"key": "val"}, |
|
|
|
|
Field4: "test", |
|
|
|
|
Field5: "test", |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
validate := New() |
|
|
|
@ -8677,16 +8697,42 @@ func TestRequiredWithout(t *testing.T) { |
|
|
|
|
if errs != nil { |
|
|
|
|
t.Fatalf("failed Error: %s", errs) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
test2 := struct { |
|
|
|
|
Field1 string `validate:"omitempty" json:"field_1"` |
|
|
|
|
Field2 *string `validate:"required_without=Field1" json:"field_2"` |
|
|
|
|
Field3 map[string]string `validate:"required_without=Field2" json:"field_3"` |
|
|
|
|
Field4 interface{} `validate:"required_without=Field3" json:"field_4"` |
|
|
|
|
Field5 string `validate:"required_without=Field3" json:"field_5"` |
|
|
|
|
Field6 string `validate:"required_without=Field1" json:"field_6"` |
|
|
|
|
}{ |
|
|
|
|
Field3: map[string]string{"key": "val"}, |
|
|
|
|
Field4: "test", |
|
|
|
|
Field5: "test", |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
errs = validate.Struct(test2) |
|
|
|
|
|
|
|
|
|
if errs == nil { |
|
|
|
|
t.Fatalf("failed Error: %s", errs) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestRequiredWithoutAll(t *testing.T) { |
|
|
|
|
|
|
|
|
|
fieldVal := "test" |
|
|
|
|
test := struct { |
|
|
|
|
Field1 *string `validate:"omitempty" json:"field_1"` |
|
|
|
|
Field2 []string `validate:"omitempty" json:"field_2"` |
|
|
|
|
Field3 string `validate:"required_without_all=Field1 Field2" json:"field_3"` |
|
|
|
|
Field1 string `validate:"omitempty" json:"field_1"` |
|
|
|
|
Field2 *string `validate:"required_without_all=Field1" json:"field_2"` |
|
|
|
|
Field3 map[string]string `validate:"required_without_all=Field2" json:"field_3"` |
|
|
|
|
Field4 interface{} `validate:"required_without_all=Field3" json:"field_4"` |
|
|
|
|
Field5 string `validate:"required_without_all=Field3" json:"field_5"` |
|
|
|
|
}{ |
|
|
|
|
Field3: "test_field3", |
|
|
|
|
Field1: "", |
|
|
|
|
Field2: &fieldVal, |
|
|
|
|
Field3: map[string]string{"key": "val"}, |
|
|
|
|
Field4: "test", |
|
|
|
|
Field5: "test", |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
validate := New() |
|
|
|
@ -8696,4 +8742,23 @@ func TestRequiredWithoutAll(t *testing.T) { |
|
|
|
|
if errs != nil { |
|
|
|
|
t.Fatalf("failed Error: %s", errs) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
test2 := struct { |
|
|
|
|
Field1 string `validate:"omitempty" json:"field_1"` |
|
|
|
|
Field2 *string `validate:"required_without_all=Field1" json:"field_2"` |
|
|
|
|
Field3 map[string]string `validate:"required_without_all=Field2" json:"field_3"` |
|
|
|
|
Field4 interface{} `validate:"required_without_all=Field3" json:"field_4"` |
|
|
|
|
Field5 string `validate:"required_without_all=Field3" json:"field_5"` |
|
|
|
|
Field6 string `validate:"required_without_all=Field1" json:"field_6"` |
|
|
|
|
}{ |
|
|
|
|
Field3: map[string]string{"key": "val"}, |
|
|
|
|
Field4: "test", |
|
|
|
|
Field5: "test", |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
errs = validate.Struct(test2) |
|
|
|
|
|
|
|
|
|
if errs == nil { |
|
|
|
|
t.Fatalf("failed Error: %s", errs) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|