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

Function TestProgramContextEvalInvalidInput

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

Source from the content-addressed store, hash-verified

4222}
4223
4224func TestProgramContextEvalInvalidInput(t *testing.T) {
4225 env, err := NewEnv()
4226 if err != nil {
4227 t.Fatalf("NewEnv() failed: %v", err)
4228 }
4229 ast, iss := env.Compile("true")
4230 if iss.Err() != nil {
4231 t.Fatalf("Compile() failed: %v", iss.Err())
4232 }
4233 prg, err := env.Program(ast)
4234 if err != nil {
4235 t.Fatalf("Program() failed: %v", err)
4236 }
4237
4238 tests := []struct {
4239 name string
4240 ctx context.Context
4241 input any
4242 wantErr string
4243 }{
4244 {
4245 name: "nil context",
4246 ctx: nil,
4247 input: map[string]any{},
4248 wantErr: "context can not be nil",
4249 },
4250 {
4251 name: "invalid input type",
4252 ctx: context.Background(),
4253 input: 123,
4254 wantErr: "invalid input, wanted Activation or map[string]any",
4255 },
4256 }
4257 for _, tc := range tests {
4258 t.Run(tc.name, func(t *testing.T) {
4259 _, _, err := prg.ContextEval(tc.ctx, tc.input)
4260 if err == nil || !strings.Contains(err.Error(), tc.wantErr) {
4261 t.Errorf("ContextEval(%v, %v) err = %v, expected error containing %q", tc.ctx, tc.input, err, tc.wantErr)
4262 }
4263 })
4264 }
4265}
4266
4267func TestOptionalOperatorsLegacyEval(t *testing.T) {
4268 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