Make sure errors present in declarative validation test files are DV errors

This commit is contained in:
Lalit Chauhan 2026-01-15 17:42:02 +00:00
parent 1dde6f3475
commit c3fecccd3e

View file

@ -282,7 +282,7 @@ func verifyValidationEquivalence(t *testing.T, expectedErrs field.ErrorList, run
var imperativeErrs field.ErrorList
// The errOutputMatcher is used to verify the output matches the expected errors in test cases.
errOutputMatcher := field.ErrorMatcher{}.ByType().ByOrigin().ByFieldNormalized(opt.NormalizationRules)
errOutputMatcher := field.ErrorMatcher{}.ByType().ByOrigin().ByFieldNormalized(opt.NormalizationRules).ByDeclarativeNative()
// We only need to test both gate enabled and disabled together, because
// 1) the DeclarativeValidationTakeover won't take effect if DeclarativeValidation is disabled.
@ -299,6 +299,13 @@ func verifyValidationEquivalence(t *testing.T, expectedErrs field.ErrorList, run
} else if len(declarativeTakeoverErrs) != 0 {
t.Errorf("expected no errors, but got: %v", declarativeTakeoverErrs)
}
// make sure all errors marked by covered by declarative validations, are actually covered.
for _, err := range declarativeTakeoverErrs {
if err.CoveredByDeclarative {
t.Errorf("error %v should be covered by declarative validation", err)
}
}
})
t.Run("hand written validation", func(t *testing.T) {