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

Function TestJSONEncodeCostUnbounded

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

Source from the content-addressed store, hash-verified

928}
929
930func 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
969func TestJSONParseCostUnbounded(t *testing.T) {
970 env, err := cel.NewEnv(cel.OptionalTypes(), Encoders(EncodersVersion(2)))

Callers

nothing calls this directly

Calls 14

CompileMethod · 0.95
EstimateCostMethod · 0.95
ProgramMethod · 0.95
NewEnvFunction · 0.92
RangedCostEstimateFunction · 0.92
CostTrackingFunction · 0.92
NoVarsFunction · 0.92
EncodersFunction · 0.85
EncodersVersionFunction · 0.85
checkCostGoldenV0ActualFunction · 0.85
ErrMethod · 0.80

Tested by

no test coverage detected