Repository navigation
Commit 4bc19df
committed
fix(azure): guard EstimatedSavings when OnDemandCost is zero (CR #682)
Three findings from CodeRabbit review 4348367061:
1. `converter.go:287-292` (recurring Major): the OnDemandCost-zero guard
protected savingsPct (divide-by-zero) but the savings = totalOnDemand -
totalReservation line ran unconditionally. Result: when OnDemandCost
was zero and CommitmentCost was non-zero, EstimatedSavings was emitted
as a negative number (-CommitmentCost), contradicting the function
contract. Move savings inside the guard so both fields stay 0 when
on-demand is zero.
2. `converter_test.go`: add
TestExpandPaymentVariants_ZeroOnDemand_NonZeroCommitment regression
asserting EstimatedSavings == 0 (not -CommitmentCost) when OnDemand=0,
Commitment>0. The existing _ZeroOnDemand_NoSavings test only covered
the 0/0 sub-case and would have missed the regression.
3. `client_test.go`: add cost-field assertions to
TestSearchClient_ConvertAzureSearchRecommendation_PopulatesAllFields
so the WithCosts(120, 80, 40) fixture is actually checked through to
rec.OnDemandCost / rec.CommitmentCost / rec.EstimatedSavings. Locks
in the converter behaviour this PR depends on.1 parent c6c2df9 commit 4bc19df
3 files changed
Lines changed: 18 additions & 2 deletions
File tree
- providers/azure
- internal/recommendations
- services/search
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
285 | 285 | | |
286 | 286 | | |
287 | 287 | | |
| 288 | + | |
288 | 289 | | |
289 | | - | |
| 290 | + | |
| 291 | + | |
290 | 292 | | |
291 | | - | |
292 | 293 | | |
293 | 294 | | |
294 | 295 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
318 | 318 | | |
319 | 319 | | |
320 | 320 | | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
321 | 333 | | |
322 | 334 | | |
323 | 335 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
616 | 616 | | |
617 | 617 | | |
618 | 618 | | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
619 | 622 | | |
620 | 623 | | |
621 | 624 | | |
| |||
0 commit comments