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

Function TestOverrideValidatorFromConfig

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

Source from the content-addressed store, hash-verified

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