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

Function testCheckCost

ext/sets_test.go:517–542  ·  view source on GitHub ↗

testCheckCost asserts the estimated cost at the latest cost model revision and at ModelVersion0, so that a case the revision moved shows both numbers side by side. wantEstV0 is nil for the common case where the revision leaves the estimate alone. Nil asserts that equivalence rather than skipping th

(t *testing.T, env *cel.Env, ast *cel.Ast, hints map[string]uint64, wantEst cost.CostEstimate, wantEstV0 *cost.CostEstimate)

Source from the content-addressed store, hash-verified

515// that equivalence rather than skipping the check, which keeps the set of non-nil entries across
516// the cost tables an exact ledger of what the revision changed.
517func testCheckCost(t *testing.T, env *cel.Env, ast *cel.Ast, hints map[string]uint64, wantEst cost.CostEstimate, wantEstV0 *cost.CostEstimate) {
518 t.Helper()
519 if len(hints) == 0 {
520 hints = map[string]uint64{}
521 }
522 estimate := func(opts ...cost.CostOption) cost.CostEstimate {
523 t.Helper()
524 est, err := env.EstimateCost(ast, testCostHintEstimator{hints: hints}, opts...)
525 if err != nil {
526 t.Fatalf("env.EstimateCost() failed: %v", err)
527 }
528 return est
529 }
530 if est := estimate(); !reflect.DeepEqual(est, wantEst) {
531 t.Errorf("env.EstimateCost() got %v, wanted %v", est, wantEst)
532 }
533 wantLegacy := wantEst
534 if wantEstV0 != nil {
535 wantLegacy = *wantEstV0
536 }
537 est := estimate(cost.ModelVersion(0))
538 if !reflect.DeepEqual(est, wantLegacy) {
539 t.Errorf("env.EstimateCost(version 0) got %v, wanted %v", est, wantLegacy)
540 }
541 checkCostGoldenV0Estimate(t, env, ast, testCostHintEstimator{hints: hints})
542}
543
544// testEvalWithCost asserts the tracked cost at the latest cost model revision and, for a checked
545// ast, at ModelVersion0.

Callers 10

TestListsCostsFunction · 0.85
TestSetsFunction · 0.85
TestBindingsFunction · 0.85
TestStringCostTrackingFunction · 0.85
TestRegexCostsFunction · 0.85
TestEncodersCostsFunction · 0.85
TestDecodeNonBase64ErrorFunction · 0.85
TestMathCostsFunction · 0.85

Calls 3

ModelVersionFunction · 0.92
EstimateCostMethod · 0.80

Tested by

no test coverage detected