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

Function TestOverrideValidatorPreservesOrder

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

Source from the content-addressed store, hash-verified

570}
571
572func TestOverrideValidatorPreservesOrder(t *testing.T) {
573 v1 := ValidateDurationLiterals()
574 v2 := ValidateComprehensionNestingLimit(2)
575 v3 := ValidateTimestampLiterals()
576
577 env1, err := NewEnv(ASTValidators(v1, v2, v3))
578 if err != nil {
579 t.Fatalf("NewEnv() failed: %v", err)
580 }
581
582 v2New := ValidateComprehensionNestingLimit(5)
583 env2, err := env1.Extend(ASTValidators(v2New))
584 if err != nil {
585 t.Fatalf("Extend() failed: %v", err)
586 }
587
588 validators := env2.Validators()
589 if len(validators) != 3 {
590 t.Fatalf("got %d validators, wanted 3", len(validators))
591 }
592 if validators[0].Name() != v1.Name() || validators[1].Name() != v2.Name() || validators[2].Name() != v3.Name() {
593 t.Fatalf("validator order or names unexpected: %v, %v, %v", validators[0].Name(), validators[1].Name(), validators[2].Name())
594 }
595 if val, ok := validators[1].(nestingLimitValidator); !ok || val.limit != 5 {
596 t.Fatalf("expected overridden nesting limit validator with limit 5, got %v", validators[1])
597 }
598}
599

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