@@ -352,6 +352,113 @@ func TestCheckIngress(t *testing.T) {
352
352
})
353
353
}
354
354
355
+ func TestCheckWarning (t * testing.T ) {
356
+
357
+ // Ensure no panic with wrong arguments
358
+ var nginx = & NGINXController {}
359
+
360
+ nginx .t = fakeTemplate {}
361
+ nginx .store = fakeIngressStore {
362
+ ingresses : []* ingress.Ingress {},
363
+ }
364
+
365
+ ing := & networking.Ingress {
366
+ ObjectMeta : metav1.ObjectMeta {
367
+ Name : "test-ingress-warning" ,
368
+ Namespace : "user-namespace" ,
369
+ Annotations : map [string ]string {},
370
+ },
371
+ Spec : networking.IngressSpec {
372
+ Rules : []networking.IngressRule {
373
+ {
374
+ Host : "example.com" ,
375
+ },
376
+ },
377
+ },
378
+ }
379
+ t .Run ("when a deprecated annotation is used a warning should be returned" , func (t * testing.T ) {
380
+ ing .ObjectMeta .Annotations [parser .GetAnnotationWithPrefix ("enable-influxdb" )] = "true"
381
+ defer func () {
382
+ ing .ObjectMeta .Annotations = map [string ]string {}
383
+ }()
384
+
385
+ warnings , err := nginx .CheckWarning (ing )
386
+ if err != nil {
387
+ t .Errorf ("no error should be returned, but %s was returned" , err )
388
+ }
389
+ if len (warnings ) != 1 {
390
+ t .Errorf ("expected 1 warning to occur but %d occured" , len (warnings ))
391
+ } else {
392
+ t .Logf ("got warning %s correctly" , warnings [0 ])
393
+ }
394
+ })
395
+
396
+ t .Run ("When an invalid pathType is used, a warning should be returned" , func (t * testing.T ) {
397
+
398
+ rules := ing .Spec .DeepCopy ().Rules
399
+ ing .Spec .Rules = []networking.IngressRule {
400
+ {
401
+ Host : "example.com" ,
402
+ IngressRuleValue : networking.IngressRuleValue {
403
+ HTTP : & networking.HTTPIngressRuleValue {
404
+ Paths : []networking.HTTPIngressPath {
405
+ {
406
+ Path : "/xpto{$2}" ,
407
+ PathType : & pathTypePrefix ,
408
+ },
409
+ {
410
+ Path : "/ok" ,
411
+ PathType : & pathTypeExact ,
412
+ },
413
+ },
414
+ },
415
+ },
416
+ },
417
+ }
418
+ defer func () {
419
+ ing .Spec .Rules = rules
420
+ }()
421
+
422
+ warnings , err := nginx .CheckWarning (ing )
423
+ if err != nil {
424
+ t .Errorf ("no error should be returned, but %s was returned" , err )
425
+ }
426
+ if len (warnings ) != 1 {
427
+ t .Errorf ("expected 1 warning to occur but %d occured" , len (warnings ))
428
+ } else {
429
+ t .Logf ("got warnings %v correctly" , warnings )
430
+ }
431
+
432
+ t .Run ("adding invalid annotations increases the warning count" , func (t * testing.T ) {
433
+ ing .ObjectMeta .Annotations [parser .GetAnnotationWithPrefix ("enable-influxdb" )] = "true"
434
+ ing .ObjectMeta .Annotations [parser .GetAnnotationWithPrefix ("secure-verify-ca-secret" )] = "true"
435
+ ing .ObjectMeta .Annotations [parser .GetAnnotationWithPrefix ("fastcgi-index" )] = "blabla"
436
+ defer func () {
437
+ ing .ObjectMeta .Annotations = map [string ]string {}
438
+ }()
439
+ warnings , err := nginx .CheckWarning (ing )
440
+ if err != nil {
441
+ t .Errorf ("no error should be returned, but %s was returned" , err )
442
+ }
443
+ if len (warnings ) != 4 {
444
+ t .Errorf ("expected 4 warning to occur but %d occured" , len (warnings ))
445
+ } else {
446
+ t .Logf ("got warnings %v correctly" , warnings )
447
+ }
448
+ })
449
+ })
450
+
451
+ t .Run ("When the ingress is marked as deleted" , func (t * testing.T ) {
452
+ ing .DeletionTimestamp = & metav1.Time {
453
+ Time : time .Now (),
454
+ }
455
+
456
+ if warnings , err := nginx .CheckWarning (ing ); err != nil || len (warnings ) != 0 {
457
+ t .Errorf ("when the ingress is marked as deleted, no warning should be returned" )
458
+ }
459
+ })
460
+ }
461
+
355
462
func TestMergeAlternativeBackends (t * testing.T ) {
356
463
testCases := map [string ]struct {
357
464
ingress * ingress.Ingress
0 commit comments