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

Function TestProgramContextEvalInvalidInput

cel/cel_test.go:4515–4556  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

4513}
4514
4515func TestProgramContextEvalInvalidInput(t *testing.T) {
4516 env, err := NewEnv()
4517 if err != nil {
4518 t.Fatalf("NewEnv() failed: %v", err)
4519 }
4520 ast, iss := env.Compile("true")
4521 if iss.Err() != nil {
4522 t.Fatalf("Compile() failed: %v", iss.Err())
4523 }
4524 prg, err := env.Program(ast)
4525 if err != nil {
4526 t.Fatalf("Program() failed: %v", err)
4527 }
4528
4529 tests := []struct {
4530 name string
4531 ctx context.Context
4532 input any
4533 wantErr string
4534 }{
4535 {
4536 name: "nil context",
4537 ctx: nil,
4538 input: map[string]any{},
4539 wantErr: "context can not be nil",
4540 },
4541 {
4542 name: "invalid input type",
4543 ctx: context.Background(),
4544 input: 123,
4545 wantErr: "invalid input, wanted Activation or map[string]any",
4546 },
4547 }
4548 for _, tc := range tests {
4549 t.Run(tc.name, func(t *testing.T) {
4550 _, _, err := prg.ContextEval(tc.ctx, tc.input)
4551 if err == nil || !strings.Contains(err.Error(), tc.wantErr) {
4552 t.Errorf("ContextEval(%v, %v) err = %v, expected error containing %q", tc.ctx, tc.input, err, tc.wantErr)
4553 }
4554 })
4555 }
4556}
4557
4558func TestOptionalOperatorsLegacyEval(t *testing.T) {
4559 tests := []struct {

Callers

nothing calls this directly

Calls 7

CompileMethod · 0.95
ProgramMethod · 0.95
ErrMethod · 0.80
NewEnvFunction · 0.70
ContextEvalMethod · 0.65
ContainsMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected