Repository navigation
Expand file tree
/
Copy pathresize_test.go
More file actions
65 lines (57 loc) · 1.88 KB
/
Copy pathresize_test.go
File metadata and controls
65 lines (57 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package common //nolint:revive // see resize.go
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestResizeCount(t *testing.T) {
t.Parallel()
monthly := 30.0
rec := Recommendation{
Count: 3, CommitmentCost: 300, OnDemandCost: 600, EstimatedSavings: 150,
SavingsPercentage: 25, BreakEvenMonths: 4, RecommendedCount: 3, RecurringMonthlyCost: &monthly,
}
got, err := ResizeCount(rec, 1)
require.NoError(t, err)
assert.Equal(t, 1, got.Count)
assert.InDelta(t, 100.0, got.CommitmentCost, 1e-9)
assert.InDelta(t, 200.0, got.OnDemandCost, 1e-9)
assert.InDelta(t, 50.0, got.EstimatedSavings, 1e-9)
require.NotNil(t, got.RecurringMonthlyCost)
assert.InDelta(t, 10.0, *got.RecurringMonthlyCost, 1e-9)
assert.Equal(t, 25.0, got.SavingsPercentage)
assert.Equal(t, 4.0, got.BreakEvenMonths)
assert.Equal(t, 3, got.RecommendedCount, "frozen pre-sizing record")
assert.Equal(t, 30.0, monthly, "input pointer untouched")
}
func TestResizeCount_NilRecurringStaysNil(t *testing.T) {
t.Parallel()
got, err := ResizeCount(Recommendation{Count: 2, CommitmentCost: 10}, 1)
require.NoError(t, err)
assert.Nil(t, got.RecurringMonthlyCost)
}
func TestResizeCount_SameCountIsIdentity(t *testing.T) {
t.Parallel()
rec := Recommendation{Count: 2, CommitmentCost: 10}
got, err := ResizeCount(rec, 2)
require.NoError(t, err)
assert.Equal(t, rec, got)
}
func TestResizeCount_RejectsInvalid(t *testing.T) {
t.Parallel()
for name, tc := range map[string]struct {
rec Recommendation
n int
}{
"zero source count": {Recommendation{Count: 0, CommitmentCost: 10}, 1},
"zero target": {Recommendation{Count: 2}, 0},
"negative target": {Recommendation{Count: 2}, -1},
"growing": {Recommendation{Count: 2}, 3},
} {
t.Run(name, func(t *testing.T) {
t.Parallel()
_, err := ResizeCount(tc.rec, tc.n)
assert.Error(t, err)
})
}
}