Merge pull request #109238 from jpbetz/reduce-time-cel-validation-tests

Flake fix: validate each expression once in primary CEL correctness suite
This commit is contained in:
Kubernetes Prow Robot 2022-04-01 17:04:08 -07:00 committed by GitHub
commit 0184d77f50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1778,38 +1778,6 @@ func TestValidationExpressions(t *testing.T) {
}
return
}
// test with cost budget exceeded
errs, _ = celValidator.Validate(ctx, field.NewPath("root"), &s, tt.obj, tt.oldObj, 0)
var found bool
for _, err := range errs {
if err.Type == field.ErrorTypeInvalid && strings.Contains(err.Error(), "validation failed due to running out of cost budget, no further validation rules will be run") {
found = true
}
}
if !found {
t.Errorf("expect cost limit exceed err but did not find")
}
if len(errs) > 1 {
t.Errorf("expect to return cost budget exceed err once")
}
// test with PerCallLimit exceeded
found = false
celValidator = NewValidator(&s, 0)
if celValidator == nil {
t.Fatal("expected non nil validator")
}
errs, _ = celValidator.Validate(ctx, field.NewPath("root"), &s, tt.obj, tt.oldObj, tt.costBudget)
for _, err := range errs {
if err.Type == field.ErrorTypeInvalid && strings.Contains(err.Error(), "no further validation rules will be run due to call cost exceeds limit for rule") {
found = true
break
}
}
if !found {
t.Errorf("expect PerCostLimit exceed err but did not find")
}
})
}
for rule, expectErrToContain := range tt.errors {
@ -1828,21 +1796,6 @@ func TestValidationExpressions(t *testing.T) {
t.Errorf("expected error to contain '%s', but got: %v", expectErrToContain, err)
}
}
// test with cost budget exceeded
errs, _ = celValidator.Validate(ctx, field.NewPath("root"), &s, tt.obj, tt.oldObj, 0)
var found bool
for _, err := range errs {
if err.Type == field.ErrorTypeInvalid && strings.Contains(err.Error(), "validation failed due to running out of cost budget, no further validation rules will be run") {
found = true
}
}
if !found {
t.Errorf("expect cost limit exceed err but did not find")
}
if len(errs) > 1 {
t.Errorf("expect to return cost budget exceed err once")
}
})
}
})