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

Function TestOverrideValidatorFromConfig

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

Source from the content-addressed store, hash-verified

548}
549
550func TestOverrideValidatorFromConfig(t *testing.T) {
551 baseEnv, err := NewEnv(
552 ASTValidators(ValidateComprehensionNestingLimit(2)),
553 )
554 if err != nil {
555 t.Fatalf("NewEnv() failed: %v", err)
556 }
557
558 conf := celenv.NewConfig("override_validator").
559 AddValidators(celenv.NewValidator(nestingLimitValidatorName).SetConfig(map[string]any{"limit": 3}))
560
561 extEnv, err := baseEnv.Extend(FromConfig(conf))
562 if err != nil {
563 t.Fatalf("baseEnv.Extend(FromConfig) failed: %v", err)
564 }
565
566 expr := `[1, 2, 3].map(i, [4, 5, 6].map(j, [7, 8, 9].map(k, i * j * k)))`
567 _, iss := extEnv.Compile(expr)
568 if iss.Err() != nil {
569 t.Fatalf("extEnv.Compile() failed: %v", iss.Err())
570 }
571}
572
573func TestOverrideValidatorPreservesOrder(t *testing.T) {
574 v1 := ValidateDurationLiterals()

Callers

nothing calls this directly

Calls 9

ExtendMethod · 0.95
ASTValidatorsFunction · 0.85
AddValidatorsMethod · 0.80
SetConfigMethod · 0.80
ErrMethod · 0.80
NewEnvFunction · 0.70
FromConfigFunction · 0.70
CompileMethod · 0.65

Tested by

no test coverage detected