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

Function TestValidateLiteralsInAsyncEnv

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

Source from the content-addressed store, hash-verified

599}
600
601func TestValidateLiteralsInAsyncEnv(t *testing.T) {
602 env, err := NewEnv(
603 ExtendedValidations(),
604 Function("async_call",
605 Overload("async_call_string", []*Type{StringType}, StringType,
606 AsyncBinding(func(ctx context.Context, args ...ref.Val) ref.Val { return args[0] }))),
607 )
608 if err != nil {
609 t.Fatalf("NewEnv() failed: %v", err)
610 }
611
612 // Duration and timestamp literal validations should succeed even in an async env.
613 _, iss := env.Compile(`duration('1h') < duration('2h') && timestamp('2023-01-01T00:00:00Z') < timestamp('2023-01-02T00:00:00Z')`)
614 if iss.Err() != nil {
615 t.Fatalf("env.Compile() valid literals failed: %v", iss.Err())
616 }
617
618 // Invalid literals should still report validation errors.
619 _, iss = env.Compile(`duration('invalid_duration')`)
620 if iss.Err() == nil {
621 t.Fatal("env.Compile() invalid duration expected error, got nil")
622 }
623
624 _, iss = env.Compile(`timestamp('invalid_timestamp')`)
625 if iss.Err() == nil {
626 t.Fatal("env.Compile() invalid timestamp expected error, got nil")
627 }
628}

Callers

nothing calls this directly

Calls 7

CompileMethod · 0.95
ExtendedValidationsFunction · 0.85
ErrMethod · 0.80
NewEnvFunction · 0.70
FunctionFunction · 0.70
OverloadFunction · 0.70
AsyncBindingFunction · 0.70

Tested by

no test coverage detected