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)
| 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. |
| 517 | func 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. |
no test coverage detected