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

Function TestJSONEncodeCostUnbounded

ext/encoders_test.go:303–338  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

301}
302
303func TestJSONEncodeCostUnbounded(t *testing.T) {
304 env, err := cel.NewEnv(Encoders(EncodersVersion(1)))
305 if err != nil {
306 t.Fatalf("cel.NewEnv() failed: %v", err)
307 }
308 ast, iss := env.Compile("json.encode('hello')")
309 if iss.Err() != nil {
310 t.Fatalf("env.Compile() failed: %v", iss.Err())
311 }
312
313 // 1. Check Cost Estimate is unbounded: Max is MaxUint64
314 est, err := env.EstimateCost(ast, testCostHintEstimator{})
315 if err != nil {
316 t.Fatalf("env.EstimateCost() failed: %v", err)
317 }
318 wantEst := checker.CostEstimate{Min: 0, Max: math.MaxUint64}
319 if est != wantEst {
320 t.Errorf("env.EstimateCost() got %v, wanted %v", est, wantEst)
321 }
322
323 // 2. Check Actual Cost is math.MaxUint64
324 prg, err := env.Program(ast, cel.CostTracking(nil))
325 if err != nil {
326 t.Fatalf("env.Program() failed: %v", err)
327 }
328 _, det, err := prg.Eval(cel.NoVars())
329 if err != nil {
330 t.Fatalf("prg.Eval() failed: %v", err)
331 }
332 if det.ActualCost() == nil {
333 t.Fatal("det.ActualCost() got nil, wanted a value")
334 }
335 if *det.ActualCost() != math.MaxUint64 {
336 t.Errorf("det.ActualCost() got %d, wanted %d", *det.ActualCost(), uint64(math.MaxUint64))
337 }
338}
339

Callers

nothing calls this directly

Calls 11

CompileMethod · 0.95
EstimateCostMethod · 0.95
ProgramMethod · 0.95
NewEnvFunction · 0.92
CostTrackingFunction · 0.92
NoVarsFunction · 0.92
EncodersFunction · 0.85
EncodersVersionFunction · 0.85
ErrMethod · 0.80
EvalMethod · 0.65
ActualCostMethod · 0.45

Tested by

no test coverage detected