@@ -136,12 +136,22 @@ func checkDeploymentHasStrategy(t *testing.T, ds *appsv1.Deployment, expected ap
136
136
t .Errorf ("deployment has unexpected strategy %q" , expected )
137
137
}
138
138
139
+ func ensureContainerDoesntHaveArg (t * testing.T , container * corev1.Container , arg string ) {
140
+ t .Helper ()
141
+
142
+ for _ , a := range container .Args {
143
+ if a == arg {
144
+ t .Errorf ("container has arg %q" , arg )
145
+ }
146
+ }
147
+ }
148
+
139
149
func TestDesiredDeployment (t * testing.T ) {
140
150
name := "deploy-test"
141
151
cntr := model .Default (fmt .Sprintf ("%s-ns" , name ), name )
142
152
icName := "test-ic"
143
153
cntr .Spec .IngressClassName = & icName
144
- testNamespaces := [] string { "ns1" , "ns2" , "ns3" }
154
+
145
155
resQutoa := corev1.ResourceRequirements {
146
156
Limits : corev1.ResourceList {
147
157
corev1 .ResourceCPU : resource .MustParse ("400m" ),
@@ -165,9 +175,6 @@ func TestDesiredDeployment(t *testing.T) {
165
175
// Change the Contour log level to test --debug.
166
176
cntr .Spec .ContourLogLevel = v1alpha1 .DebugLog
167
177
168
- // Change the Contour watch namespaces flag
169
- cntr .Spec .WatchNamespaces = testNamespaces
170
-
171
178
cntr .Spec .ResourceLabels = map [string ]string {
172
179
"key" : "value" ,
173
180
}
@@ -211,14 +218,53 @@ func TestDesiredDeployment(t *testing.T) {
211
218
arg = fmt .Sprintf ("--kubernetes-debug=%d" , cntr .Spec .KubernetesLogLevel )
212
219
checkContainerHasArg (t , container , arg )
213
220
214
- arg = fmt .Sprintf ("--watch-namespaces=%s" , strings .Join (testNamespaces , "," ))
215
- checkContainerHasArg (t , container , arg )
216
-
217
221
checkDeploymentHasNodeSelector (t , deploy , nil )
218
222
checkDeploymentHasTolerations (t , deploy , nil )
219
223
checkDeploymentHasResourceRequirements (t , deploy , resQutoa )
220
224
checkDeploymentHasStrategy (t , deploy , cntr .Spec .ContourDeploymentStrategy )
225
+ }
221
226
227
+ func TestDesiredDeploymentWhenSettingWatchNamespaces (t * testing.T ) {
228
+ testCases := []struct {
229
+ description string
230
+ namespaces []string
231
+ expectArgExist bool
232
+ }{
233
+ {
234
+ description : "several valid namespaces" ,
235
+ namespaces : []string {"ns1" , "ns2" },
236
+ expectArgExist : true ,
237
+ },
238
+ {
239
+ description : "single valid namespace" ,
240
+ namespaces : []string {"ns1" , "ns2" },
241
+ expectArgExist : true ,
242
+ },
243
+ {
244
+ description : "include empty namespace" ,
245
+ namespaces : []string {"ns1" , "" },
246
+ expectArgExist : false ,
247
+ },
248
+ }
249
+
250
+ for _ , tc := range testCases {
251
+ t .Run (tc .description , func (t * testing.T ) {
252
+ name := "deploy-test"
253
+ cntr := model .Default (fmt .Sprintf ("%s-ns" , name ), name )
254
+ icName := "test-ic"
255
+ cntr .Spec .IngressClassName = & icName
256
+ // Change the Contour watch namespaces flag
257
+ cntr .Spec .WatchNamespaces = tc .namespaces
258
+ deploy := DesiredDeployment (cntr , "ghcr.io/projectcontour/contour:test" )
259
+ container := checkDeploymentHasContainer (t , deploy , contourContainerName , true )
260
+ arg := fmt .Sprintf ("--watch-namespaces=%s" , strings .Join (tc .namespaces , "," ))
261
+ if tc .expectArgExist {
262
+ checkContainerHasArg (t , container , arg )
263
+ } else {
264
+ ensureContainerDoesntHaveArg (t , container , arg )
265
+ }
266
+ })
267
+ }
222
268
}
223
269
224
270
func TestNodePlacementDeployment (t * testing.T ) {
0 commit comments