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

Function TestProgramEvalInvalidInput

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

Source from the content-addressed store, hash-verified

5297}
5298
5299func TestProgramEvalInvalidInput(t *testing.T) {
5300 env, err := NewEnv()
5301 if err != nil {
5302 t.Fatalf("NewEnv() failed: %v", err)
5303 }
5304 ast, iss := env.Compile("true")
5305 if iss.Err() != nil {
5306 t.Fatalf("Compile() failed: %v", iss.Err())
5307 }
5308 prg, err := env.Program(ast)
5309 if err != nil {
5310 t.Fatalf("Program() failed: %v", err)
5311 }
5312
5313 tests := []struct {
5314 name string
5315 input any
5316 wantErr string
5317 }{
5318 {
5319 name: "int input",
5320 input: 123,
5321 wantErr: "invalid input, wanted Activation or map[string]any",
5322 },
5323 {
5324 name: "nil input",
5325 input: nil,
5326 wantErr: "invalid input, wanted Activation or map[string]any",
5327 },
5328 }
5329 for _, tc := range tests {
5330 t.Run(tc.name, func(t *testing.T) {
5331 _, _, err := prg.Eval(tc.input)
5332 if err == nil || !strings.Contains(err.Error(), tc.wantErr) {
5333 t.Errorf("Eval(%v) err = %v, expected error containing %q", tc.input, err, tc.wantErr)
5334 }
5335 })
5336 }
5337}
5338
5339func TestProgramContextEvalInvalidInput(t *testing.T) {
5340 env, err := NewEnv()

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected