Skip to content

Commit

Permalink
skip_unless better test assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
deankarn committed Apr 29, 2023
1 parent 5ddd99c commit adcf335
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10905,19 +10905,28 @@ func TestSkipUnless(t *testing.T) {
Equal(t, len(ve), 1)
AssertError(t, errs, "Field5", "Field5", "Field5", "Field5", "skip_unless")

defer func() {
if r := recover(); r == nil {
t.Errorf("test3 should have panicked!")
}
}()

test3 := struct {
Inner *Inner
Field1 string `validate:"skip_unless=Inner.Field" json:"field_1"`
}{
Inner: &Inner{Field: &fieldVal},
}
_ = validate.Struct(test3)
PanicMatches(t, func() {
_ = validate.Struct(test3)
}, "Bad param number for skip_unless Field1")

test4 := struct {
Inner *Inner
Field1 string `validate:"skip_unless=Inner.Field test1" json:"field_1"`
}{
Inner: &Inner{Field: &fieldVal},
}
errs = validate.Struct(test4)
NotEqual(t, errs, nil)

ve = errs.(ValidationErrors)
Equal(t, len(ve), 1)
AssertError(t, errs, "Field1", "Field1", "Field1", "Field1", "skip_unless")
}

func TestRequiredWith(t *testing.T) {
Expand Down Expand Up @@ -12913,4 +12922,4 @@ func TestCronExpressionValidation(t *testing.T) {
}
}
}
}
}

0 comments on commit adcf335

Please sign in to comment.