(t *testing.T)
| 301 | } |
| 302 | |
| 303 | func 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 |
nothing calls this directly
no test coverage detected