mirror of
https://github.com/kubernetes/kubernetes.git
synced 2026-06-09 00:34:10 -04:00
Fix testing utils
This commit is contained in:
parent
89fb0b9b3e
commit
68ad19102c
1 changed files with 11 additions and 2 deletions
|
|
@ -424,12 +424,21 @@ func verifyValidationEquivalence(t *testing.T, expectedErrs field.ErrorList, run
|
|||
testCtx := rest.WithAllDeclarativeEnforcedForTest(ctx)
|
||||
allDeclarativeErrs := runValidations(testCtx)
|
||||
|
||||
// In this mode, strategy.go validation remove all hand written validations errors which are marked covered by DV.
|
||||
// so we have to filter out errors which are filtered out by strategy.go.
|
||||
// This is because DV will not return those errors due to short circuiting of validations at the parent node.
|
||||
filteredExpectedErrors := make(field.ErrorList, 0, len(expectedErrs))
|
||||
for _, err := range expectedErrs {
|
||||
if !err.ShortCircuitedInDV {
|
||||
filteredExpectedErrors = append(filteredExpectedErrors, err)
|
||||
}
|
||||
}
|
||||
// The matcher here is more specific to ensure that errors from Alpha rules
|
||||
// are included and matched correctly.
|
||||
// This also ensure that errors are coming from the declarative validations only.
|
||||
dvErrorMatcher := errOutputMatcher.ByValidationStabilityLevel().BySource()
|
||||
if len(expectedErrs) > 0 {
|
||||
dvErrorMatcher.Test(t, expectedErrs, allDeclarativeErrs)
|
||||
if len(filteredExpectedErrors) > 0 {
|
||||
dvErrorMatcher.Test(t, filteredExpectedErrors, allDeclarativeErrs)
|
||||
} else if len(allDeclarativeErrs) != 0 {
|
||||
t.Errorf("expected no errors, but got: %v", allDeclarativeErrs)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue