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

Function TestProgramContextEvalInvalidInput

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

Source from the content-addressed store, hash-verified

4116}
4117
4118func TestProgramContextEvalInvalidInput(t *testing.T) {
4119 env, err := NewEnv()
4120 if err != nil {
4121 t.Fatalf("NewEnv() failed: %v", err)
4122 }
4123 ast, iss := env.Compile("true")
4124 if iss.Err() != nil {
4125 t.Fatalf("Compile() failed: %v", iss.Err())
4126 }
4127 prg, err := env.Program(ast)
4128 if err != nil {
4129 t.Fatalf("Program() failed: %v", err)
4130 }
4131
4132 tests := []struct {
4133 name string
4134 ctx context.Context
4135 input any
4136 wantErr string
4137 }{
4138 {
4139 name: "nil context",
4140 ctx: nil,
4141 input: map[string]any{},
4142 wantErr: "context can not be nil",
4143 },
4144 {
4145 name: "invalid input type",
4146 ctx: context.Background(),
4147 input: 123,
4148 wantErr: "invalid input, wanted Activation or map[string]any",
4149 },
4150 }
4151 for _, tc := range tests {
4152 t.Run(tc.name, func(t *testing.T) {
4153 _, _, err := prg.ContextEval(tc.ctx, tc.input)
4154 if err == nil || !strings.Contains(err.Error(), tc.wantErr) {
4155 t.Errorf("ContextEval(%v, %v) err = %v, expected error containing %q", tc.ctx, tc.input, err, tc.wantErr)
4156 }
4157 })
4158 }
4159}
4160
4161func TestOptionalOperatorsLegacyEval(t *testing.T) {
4162 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