-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
validation_test.go
143 lines (110 loc) · 3.81 KB
/
validation_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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package v1alpha5
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("ConfigFile ssh flags validation", func() {
var (
testKeyPath = "some/path/to/file.pub"
testKeyName = "id_rsa.pub"
testKey = "THIS IS A KEY"
)
It("fails when a key path and a key name are specified", func() {
SSHConfig := &NodeGroupSSH{
Allow: Enabled(),
PublicKeyPath: &testKeyPath,
PublicKeyName: &testKeyName,
}
checkItDetectsError(SSHConfig)
})
It("fails when a key path and a key are specified", func() {
SSHConfig := &NodeGroupSSH{
Allow: Enabled(),
PublicKeyPath: &testKeyPath,
PublicKey: &testKey,
}
checkItDetectsError(SSHConfig)
})
It("fails when a key name and a key are specified", func() {
SSHConfig := &NodeGroupSSH{
Allow: Enabled(),
PublicKeyName: &testKeyName,
PublicKey: &testKey,
}
checkItDetectsError(SSHConfig)
})
It("It doesn't panic when SSH is not enabled", func() {
err := validateNodeGroupSSH(nil)
Expect(err).ToNot(HaveOccurred())
})
Context("Instances distribution", func() {
var ng *NodeGroup
BeforeEach(func() {
ng = &NodeGroup{
InstancesDistribution: &NodeGroupInstancesDistribution{
InstanceTypes: []string{"t3.medium", "t3.large"},
},
}
})
It("It doesn't panic when instance distribution is not enabled", func() {
ng.InstancesDistribution = nil
err := validateInstancesDistribution(ng)
Expect(err).ToNot(HaveOccurred())
})
It("It fails when instance distribution is enabled and instanceType is not empty or \"mixed\"", func() {
err := validateInstancesDistribution(ng)
Expect(err).ToNot(HaveOccurred())
ng.InstanceType = "t3.small"
err = validateInstancesDistribution(ng)
Expect(err).To(HaveOccurred())
})
It("It fails when the instance distribution doesn't have at least 2 different instance types", func() {
ng.InstanceType = "mixed"
ng.InstancesDistribution.InstanceTypes = []string{"t3.medium", "t3.medium"}
err := validateInstancesDistribution(ng)
Expect(err).To(HaveOccurred())
ng.InstanceType = "mixed"
ng.InstancesDistribution.InstanceTypes = []string{"t3.medium", "t3.small"}
err = validateInstancesDistribution(ng)
Expect(err).ToNot(HaveOccurred())
})
It("It fails when the onDemandBaseCapacity is not above 0", func() {
ng.InstancesDistribution.OnDemandBaseCapacity = newInt(-1)
err := validateInstancesDistribution(ng)
Expect(err).To(HaveOccurred())
ng.InstancesDistribution.OnDemandBaseCapacity = newInt(1)
err = validateInstancesDistribution(ng)
Expect(err).ToNot(HaveOccurred())
})
It("It fails when the spotInstancePools is not between 1 and 20", func() {
ng.InstancesDistribution.SpotInstancePools = newInt(0)
err := validateInstancesDistribution(ng)
Expect(err).To(HaveOccurred())
ng.InstancesDistribution.SpotInstancePools = newInt(21)
err = validateInstancesDistribution(ng)
Expect(err).To(HaveOccurred())
ng.InstancesDistribution.SpotInstancePools = newInt(2)
err = validateInstancesDistribution(ng)
Expect(err).ToNot(HaveOccurred())
})
It("It fails when the percentageAboveBase is not between 0 and 100", func() {
ng.InstancesDistribution.OnDemandPercentageAboveBaseCapacity = newInt(-1)
err := validateInstancesDistribution(ng)
Expect(err).To(HaveOccurred())
ng.InstancesDistribution.OnDemandPercentageAboveBaseCapacity = newInt(101)
err = validateInstancesDistribution(ng)
Expect(err).To(HaveOccurred())
ng.InstancesDistribution.OnDemandPercentageAboveBaseCapacity = newInt(50)
err = validateInstancesDistribution(ng)
Expect(err).ToNot(HaveOccurred())
})
})
})
func checkItDetectsError(SSHConfig *NodeGroupSSH) {
err := validateNodeGroupSSH(SSHConfig)
Expect(err).To(HaveOccurred())
}
func newInt(value int) *int {
v := value
return &v
}