-
-
Notifications
You must be signed in to change notification settings - Fork 90
/
Copy pathautoscaling_test.go
124 lines (117 loc) · 2.72 KB
/
autoscaling_test.go
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package ecspresso_test
import (
"testing"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/google/go-cmp/cmp"
"github.com/kayac/ecspresso/v2"
)
func TestModifyAutoScalingParams_String(t *testing.T) {
testCases := []struct {
name string
params ecspresso.ModifyAutoScalingParams
expected string
}{
{
name: "all values set",
params: ecspresso.ModifyAutoScalingParams{
Suspend: aws.Bool(false),
MinCapacity: aws.Int32(1),
MaxCapacity: aws.Int32(5),
},
expected: "MaxCapacity=5,MinCapacity=1,Suspend=false",
},
{
name: "only Suspend set",
params: ecspresso.ModifyAutoScalingParams{
Suspend: aws.Bool(true),
},
expected: "Suspend=true",
},
{
name: "only MinCapacity set",
params: ecspresso.ModifyAutoScalingParams{
MinCapacity: aws.Int32(1),
},
expected: "MinCapacity=1",
},
{
name: "only MaxCapacity set",
params: ecspresso.ModifyAutoScalingParams{
MaxCapacity: aws.Int32(5),
},
expected: "MaxCapacity=5",
},
{
name: "all values nil",
params: ecspresso.ModifyAutoScalingParams{},
expected: "",
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
result := tc.params.String()
if result != tc.expected {
t.Errorf("Expected '%s', but got '%s'", tc.expected, result)
}
})
}
}
func TestModifyAutoScalingParams(t *testing.T) {
tests := []struct {
name string
opt ecspresso.DeployOption
expected *ecspresso.ModifyAutoScalingParams
}{
{
name: "SuspendAutoScaling=true",
opt: ecspresso.DeployOption{
SuspendAutoScaling: aws.Bool(true),
},
expected: &ecspresso.ModifyAutoScalingParams{
Suspend: aws.Bool(true),
MinCapacity: nil,
MaxCapacity: nil,
},
},
{
name: "ResumeAutoScaling=true",
opt: ecspresso.DeployOption{
ResumeAutoScaling: aws.Bool(true),
},
expected: &ecspresso.ModifyAutoScalingParams{
Suspend: aws.Bool(false),
MinCapacity: nil,
MaxCapacity: nil,
},
},
{
name: "AutoScalingMin and AutoScalingMax are specified",
opt: ecspresso.DeployOption{
AutoScalingMin: aws.Int32(1),
AutoScalingMax: aws.Int32(10),
},
expected: &ecspresso.ModifyAutoScalingParams{
Suspend: nil,
MinCapacity: aws.Int32(1),
MaxCapacity: aws.Int32(10),
},
},
{
name: "Default values",
opt: ecspresso.DeployOption{},
expected: &ecspresso.ModifyAutoScalingParams{
Suspend: nil,
MinCapacity: nil,
MaxCapacity: nil,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
p := tt.opt.ModifyAutoScalingParams()
if diff := cmp.Diff(p, tt.expected); diff != "" {
t.Errorf("ModifyAutoScalingParams() mismatch (-want +got):\n%s", diff)
}
})
}
}