@@ -18,14 +18,14 @@ func TestNginxProxyKubernetes(t *testing.T) {
18
18
g .Expect (err ).ToNot (HaveOccurred ())
19
19
20
20
tests := []struct {
21
- policySpec ngfAPIv1alpha2.NginxProxySpec
21
+ spec ngfAPIv1alpha2.NginxProxySpec
22
22
name string
23
23
wantErrors []string
24
24
}{
25
25
{
26
26
name : "Validate NginxProxy with both Deployment and DaemonSet is invalid" ,
27
27
wantErrors : []string {expectedOneOfDeploymentOrDaemonSetError },
28
- policySpec : ngfAPIv1alpha2.NginxProxySpec {
28
+ spec : ngfAPIv1alpha2.NginxProxySpec {
29
29
Kubernetes : & ngfAPIv1alpha2.KubernetesSpec {
30
30
Deployment : & ngfAPIv1alpha2.DeploymentSpec {},
31
31
DaemonSet : & ngfAPIv1alpha2.DaemonSetSpec {},
@@ -34,15 +34,15 @@ func TestNginxProxyKubernetes(t *testing.T) {
34
34
},
35
35
{
36
36
name : "Validate NginxProxy with Deployment only is valid" ,
37
- policySpec : ngfAPIv1alpha2.NginxProxySpec {
37
+ spec : ngfAPIv1alpha2.NginxProxySpec {
38
38
Kubernetes : & ngfAPIv1alpha2.KubernetesSpec {
39
39
Deployment : & ngfAPIv1alpha2.DeploymentSpec {},
40
40
},
41
41
},
42
42
},
43
43
{
44
44
name : "Validate NginxProxy with DaemonSet only is valid" ,
45
- policySpec : ngfAPIv1alpha2.NginxProxySpec {
45
+ spec : ngfAPIv1alpha2.NginxProxySpec {
46
46
Kubernetes : & ngfAPIv1alpha2.KubernetesSpec {
47
47
DaemonSet : & ngfAPIv1alpha2.DaemonSetSpec {},
48
48
},
@@ -53,15 +53,15 @@ func TestNginxProxyKubernetes(t *testing.T) {
53
53
for _ , tt := range tests {
54
54
t .Run (tt .name , func (t * testing.T ) {
55
55
t .Parallel ()
56
- policySpec := tt .policySpec
56
+ spec := tt .spec
57
57
policyName := uniqueResourceName (testPolicyName )
58
58
59
59
nginxProxy := & ngfAPIv1alpha2.NginxProxy {
60
60
ObjectMeta : controllerruntime.ObjectMeta {
61
61
Name : policyName ,
62
62
Namespace : defaultNamespace ,
63
63
},
64
- Spec : policySpec ,
64
+ Spec : spec ,
65
65
}
66
66
validateCrd (t , tt .wantErrors , g , nginxProxy , k8sClient )
67
67
})
@@ -76,22 +76,22 @@ func TestNginxProxyRewriteClientIP(t *testing.T) {
76
76
g .Expect (err ).ToNot (HaveOccurred ())
77
77
78
78
tests := []struct {
79
- policySpec ngfAPIv1alpha2.NginxProxySpec
79
+ spec ngfAPIv1alpha2.NginxProxySpec
80
80
name string
81
81
wantErrors []string
82
82
}{
83
83
{
84
84
name : "Validate NginxProxy is invalid when trustedAddresses is not set and mode is set" ,
85
85
wantErrors : []string {expectedIfModeSetTrustedAddressesError },
86
- policySpec : ngfAPIv1alpha2.NginxProxySpec {
86
+ spec : ngfAPIv1alpha2.NginxProxySpec {
87
87
RewriteClientIP : & ngfAPIv1alpha2.RewriteClientIP {
88
88
Mode : helpers.GetPointer [ngfAPIv1alpha2.RewriteClientIPModeType ]("XForwardedFor" ),
89
89
},
90
90
},
91
91
},
92
92
{
93
93
name : "Validate NginxProxy is valid when both mode and trustedAddresses are set" ,
94
- policySpec : ngfAPIv1alpha2.NginxProxySpec {
94
+ spec : ngfAPIv1alpha2.NginxProxySpec {
95
95
RewriteClientIP : & ngfAPIv1alpha2.RewriteClientIP {
96
96
Mode : helpers.GetPointer [ngfAPIv1alpha2.RewriteClientIPModeType ]("XForwardedFor" ),
97
97
TrustedAddresses : []ngfAPIv1alpha2.RewriteClientIPAddress {
@@ -108,15 +108,86 @@ func TestNginxProxyRewriteClientIP(t *testing.T) {
108
108
for _ , tt := range tests {
109
109
t .Run (tt .name , func (t * testing.T ) {
110
110
t .Parallel ()
111
- policySpec := tt .policySpec
111
+ spec := tt .spec
112
112
policyName := uniqueResourceName (testPolicyName )
113
113
114
114
nginxProxy := & ngfAPIv1alpha2.NginxProxy {
115
115
ObjectMeta : controllerruntime.ObjectMeta {
116
116
Name : policyName ,
117
117
Namespace : defaultNamespace ,
118
118
},
119
- Spec : policySpec ,
119
+ Spec : spec ,
120
+ }
121
+ validateCrd (t , tt .wantErrors , g , nginxProxy , k8sClient )
122
+ })
123
+ }
124
+ }
125
+
126
+ func TestNginxProxyAutoscaling (t * testing.T ) {
127
+ t .Parallel ()
128
+ g := NewWithT (t )
129
+
130
+ k8sClient , err := getKubernetesClient (t )
131
+ g .Expect (err ).ToNot (HaveOccurred ())
132
+
133
+ tests := []struct {
134
+ spec ngfAPIv1alpha2.NginxProxySpec
135
+ name string
136
+ wantErrors []string
137
+ }{
138
+ {
139
+ name : "Validate NginxProxy is invalid when MinReplicas not less than, or equal to MaxReplicas" ,
140
+ wantErrors : []string {expectedMinReplicasLessThanOrEqualError },
141
+ spec : ngfAPIv1alpha2.NginxProxySpec {
142
+ Kubernetes : & ngfAPIv1alpha2.KubernetesSpec {
143
+ Deployment : & ngfAPIv1alpha2.DeploymentSpec {
144
+ Autoscaling : & ngfAPIv1alpha2.AutoscalingSpec {
145
+ MinReplicas : helpers.GetPointer [int32 ](10 ),
146
+ MaxReplicas : 5 ,
147
+ },
148
+ },
149
+ },
150
+ },
151
+ },
152
+ {
153
+ name : "Validate NginxProxy is valid when MinReplicas is less than MaxReplicas" ,
154
+ spec : ngfAPIv1alpha2.NginxProxySpec {
155
+ Kubernetes : & ngfAPIv1alpha2.KubernetesSpec {
156
+ Deployment : & ngfAPIv1alpha2.DeploymentSpec {
157
+ Autoscaling : & ngfAPIv1alpha2.AutoscalingSpec {
158
+ MinReplicas : helpers.GetPointer [int32 ](1 ),
159
+ MaxReplicas : 5 ,
160
+ },
161
+ },
162
+ },
163
+ },
164
+ },
165
+ {
166
+ name : "Validate NginxProxy is valid when MinReplicas is equal to MaxReplicas" ,
167
+ spec : ngfAPIv1alpha2.NginxProxySpec {
168
+ Kubernetes : & ngfAPIv1alpha2.KubernetesSpec {
169
+ Deployment : & ngfAPIv1alpha2.DeploymentSpec {
170
+ Autoscaling : & ngfAPIv1alpha2.AutoscalingSpec {
171
+ MinReplicas : helpers.GetPointer [int32 ](5 ),
172
+ MaxReplicas : 5 ,
173
+ },
174
+ },
175
+ },
176
+ },
177
+ },
178
+ }
179
+ for _ , tt := range tests {
180
+ t .Run (tt .name , func (t * testing.T ) {
181
+ t .Parallel ()
182
+ spec := tt .spec
183
+ policyName := uniqueResourceName (testPolicyName )
184
+
185
+ nginxProxy := & ngfAPIv1alpha2.NginxProxy {
186
+ ObjectMeta : controllerruntime.ObjectMeta {
187
+ Name : policyName ,
188
+ Namespace : defaultNamespace ,
189
+ },
190
+ Spec : spec ,
120
191
}
121
192
validateCrd (t , tt .wantErrors , g , nginxProxy , k8sClient )
122
193
})
0 commit comments