(t *testing.T)
| 928 | } |
| 929 | |
| 930 | func TestJSONEncodeCostUnbounded(t *testing.T) { |
| 931 | env, err := cel.NewEnv(Encoders(EncodersVersion(1))) |
| 932 | if err != nil { |
| 933 | t.Fatalf("cel.NewEnv() failed: %v", err) |
| 934 | } |
| 935 | ast, iss := env.Compile("json.encode('hello')") |
| 936 | if iss.Err() != nil { |
| 937 | t.Fatalf("env.Compile() failed: %v", iss.Err()) |
| 938 | } |
| 939 | |
| 940 | // 1. Check Cost Estimate is unbounded: Max is MaxUint64 |
| 941 | est, err := env.EstimateCost(ast, testCostHintEstimator{}) |
| 942 | if err != nil { |
| 943 | t.Fatalf("env.EstimateCost() failed: %v", err) |
| 944 | } |
| 945 | wantEst := cost.RangedCostEstimate(1, math.MaxUint64) |
| 946 | if est != wantEst { |
| 947 | t.Errorf("env.EstimateCost() got %v, wanted %v", est, wantEst) |
| 948 | } |
| 949 | |
| 950 | // 2. Check Actual Cost is math.MaxUint64 |
| 951 | prg, err := env.Program(ast, cel.CostTracking(nil)) |
| 952 | if err != nil { |
| 953 | t.Fatalf("env.Program() failed: %v", err) |
| 954 | } |
| 955 | _, det, err := prg.Eval(cel.NoVars()) |
| 956 | if err != nil { |
| 957 | t.Fatalf("prg.Eval() failed: %v", err) |
| 958 | } |
| 959 | if det.ActualCost() == nil { |
| 960 | t.Fatal("det.ActualCost() got nil, wanted a value") |
| 961 | } |
| 962 | if *det.ActualCost() != math.MaxUint64 { |
| 963 | t.Errorf("det.ActualCost() got %d, wanted %d", *det.ActualCost(), uint64(math.MaxUint64)) |
| 964 | } |
| 965 | checkCostGoldenV0Estimate(t, env, ast, testCostHintEstimator{}) |
| 966 | checkCostGoldenV0Actual(t, env, ast, nil) |
| 967 | } |
| 968 | |
| 969 | func TestJSONParseCostUnbounded(t *testing.T) { |
| 970 | env, err := cel.NewEnv(cel.OptionalTypes(), Encoders(EncodersVersion(2))) |
nothing calls this directly
no test coverage detected