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

Function TestMemoryLimit

cel/memory_test.go:160–201  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

158}
159
160func TestMemoryLimit(t *testing.T) {
161 tests := []struct {
162 name string
163 memLimit uint32
164 wantErr string
165 }{
166 {
167 name: "under_limit",
168 memLimit: 1000,
169 },
170 {
171 name: "over_limit",
172 memLimit: 5,
173 wantErr: "memory limit exceeded",
174 },
175 }
176 for _, tst := range tests {
177 tc := tst
178 t.Run(tc.name, func(t *testing.T) {
179 t.Parallel()
180 env := testEnv(t, Variable("a", ListType(IntType)))
181 ast, iss := env.Compile(`a + a`)
182 if iss.Err() != nil {
183 t.Fatalf("env.Compile() failed: %v", iss.Err())
184 }
185 program, err := env.Program(ast, MemoryLimit(tc.memLimit))
186 if err != nil {
187 t.Fatalf("env.Program() failed: %v", err)
188 }
189 _, _, err = program.Eval(map[string]any{"a": []int64{1, 2, 3}})
190 if tc.wantErr == "" {
191 if err != nil {
192 t.Fatalf("program.Eval() failed: %v", err)
193 }
194 return
195 }
196 if err == nil || !strings.Contains(err.Error(), tc.wantErr) {
197 t.Fatalf("program.Eval() got error %v, wanted error containing %q", err, tc.wantErr)
198 }
199 })
200 }
201}
202
203func TestMemoryTrackingCalculationLimitExceeded(t *testing.T) {
204 env := testEnv(t, Variable("a", ListType(StringType)))

Callers

nothing calls this directly

Calls 9

MemoryLimitFunction · 0.85
ErrMethod · 0.80
ProgramMethod · 0.80
testEnvFunction · 0.70
VariableFunction · 0.70
CompileMethod · 0.65
EvalMethod · 0.65
ContainsMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected