MCPcopy Create free account
hub / github.com/cel-expr/cel-go / TestOverrideValidatorPreservesOrder

Function TestOverrideValidatorPreservesOrder

cel/validator_test.go:501–527  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

499}
500
501func TestOverrideValidatorPreservesOrder(t *testing.T) {
502 v1 := ValidateDurationLiterals()
503 v2 := ValidateComprehensionNestingLimit(2)
504 v3 := ValidateTimestampLiterals()
505
506 env1, err := NewEnv(ASTValidators(v1, v2, v3))
507 if err != nil {
508 t.Fatalf("NewEnv() failed: %v", err)
509 }
510
511 v2New := ValidateComprehensionNestingLimit(5)
512 env2, err := env1.Extend(ASTValidators(v2New))
513 if err != nil {
514 t.Fatalf("Extend() failed: %v", err)
515 }
516
517 validators := env2.Validators()
518 if len(validators) != 3 {
519 t.Fatalf("got %d validators, wanted 3", len(validators))
520 }
521 if validators[0].Name() != v1.Name() || validators[1].Name() != v2.Name() || validators[2].Name() != v3.Name() {
522 t.Fatalf("validator order or names unexpected: %v, %v, %v", validators[0].Name(), validators[1].Name(), validators[2].Name())
523 }
524 if val, ok := validators[1].(nestingLimitValidator); !ok || val.limit != 5 {
525 t.Fatalf("expected overridden nesting limit validator with limit 5, got %v", validators[1])
526 }
527}
528

Callers

nothing calls this directly

Calls 8

ExtendMethod · 0.95
ValidateDurationLiteralsFunction · 0.85
ASTValidatorsFunction · 0.85
ValidatorsMethod · 0.80
NewEnvFunction · 0.70
NameMethod · 0.65

Tested by

no test coverage detected