@@ -7,15 +7,16 @@ import (
7
7
"net/http"
8
8
"testing"
9
9
10
+ yaml "gopkg.in/yaml.v2"
11
+
10
12
"github.com/TykTechnologies/tyk-k8s/tyk"
11
13
"github.com/TykTechnologies/tyk-sync/clients/objects"
12
- "gopkg.in/yaml.v2"
13
14
"k8s.io/api/networking/v1beta1"
14
15
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
15
16
"k8s.io/apimachinery/pkg/util/intstr"
16
17
)
17
18
18
- var lastResponse = ""
19
+ var lastResponse string
19
20
var running = false
20
21
21
22
func serverSetup () {
@@ -63,12 +64,12 @@ func TestControlServer_noPaths(t *testing.T) {
63
64
apiVersion: networking/v1beta1
64
65
kind: Ingress
65
66
metadata:
66
- name: cafe-ingress
67
- annotations:
68
- kubernetes.io/ingress.class: tyk
67
+ name: cafe-ingress
68
+ annotations:
69
+ kubernetes.io/ingress.class: tyk
69
70
spec:
70
- rules:
71
- - host: cafe.example.com
71
+ rules:
72
+ - host: cafe.example.com
72
73
`
73
74
74
75
go serverSetup ()
@@ -177,7 +178,7 @@ func TestControlServer_doAddWithCustomTemplate(t *testing.T) {
177
178
HTTP : & v1beta1.HTTPIngressRuleValue {
178
179
Paths : []v1beta1.HTTPIngressPath {
179
180
{
180
- Path : "/" ,
181
+ Path : "/foo " ,
181
182
Backend : v1beta1.IngressBackend {
182
183
ServiceName : "foo-service" ,
183
184
ServicePort : intstr.IntOrString {IntVal : 80 , StrVal : "80" },
@@ -202,7 +203,6 @@ func TestControlServer_doAddWithCustomTemplate(t *testing.T) {
202
203
if err != nil {
203
204
t .Fatal (err )
204
205
}
205
-
206
206
def := & objects.DBApiDefinition {}
207
207
err = json .Unmarshal ([]byte (lastResponse ), def )
208
208
if err != nil {
@@ -225,12 +225,11 @@ func TestControlServer_doAddWithCustomTemplate(t *testing.T) {
225
225
lastResponse = ""
226
226
}
227
227
228
- var ingTests = []struct {
229
- name string
230
- in * v1beta1.Ingress
231
- out * v1beta1.Ingress
228
+ var ingTests = map [string ]struct {
229
+ in * v1beta1.Ingress
230
+ out * v1beta1.Ingress
232
231
}{
233
- { "changed host" , & v1beta1.Ingress {
232
+ "changed host" : { & v1beta1.Ingress {
234
233
ObjectMeta : v1.ObjectMeta {
235
234
Name : "foo-name" ,
236
235
Namespace : "bar-namespace" ,
@@ -287,8 +286,7 @@ var ingTests = []struct {
287
286
},
288
287
},
289
288
},
290
- },
291
- {"changed path" , & v1beta1.Ingress {
289
+ }, "changed path" : {& v1beta1.Ingress {
292
290
ObjectMeta : v1.ObjectMeta {
293
291
Name : "foo-name" ,
294
292
Namespace : "bar-namespace" ,
@@ -345,9 +343,7 @@ var ingTests = []struct {
345
343
},
346
344
},
347
345
},
348
- },
349
- // changed service name
350
- {"changed service name" , & v1beta1.Ingress {
346
+ }, "changed service name" : {& v1beta1.Ingress {
351
347
ObjectMeta : v1.ObjectMeta {
352
348
Name : "foo-name" ,
353
349
Namespace : "bar-namespace" ,
@@ -404,9 +400,7 @@ var ingTests = []struct {
404
400
},
405
401
},
406
402
},
407
- },
408
- //changed service port
409
- {"changed service port" , & v1beta1.Ingress {
403
+ }, "changed service port" : {& v1beta1.Ingress {
410
404
ObjectMeta : v1.ObjectMeta {
411
405
Name : "foo-name" ,
412
406
Namespace : "bar-namespace" ,
@@ -463,18 +457,79 @@ var ingTests = []struct {
463
457
},
464
458
},
465
459
},
460
+ }, "changed annotation" : {& v1beta1.Ingress {
461
+ ObjectMeta : v1.ObjectMeta {
462
+ Name : "foo-name" ,
463
+ Namespace : "bar-namespace" ,
464
+ Annotations : map [string ]string {
465
+ IngressAnnotation : IngressAnnotationValue ,
466
+ "bool.service.tyk.io/use-keyless" : "false" ,
467
+ },
468
+ },
469
+ Spec : v1beta1.IngressSpec {
470
+ Rules : []v1beta1.IngressRule {
471
+ {
472
+ Host : "foo.com" ,
473
+ IngressRuleValue : v1beta1.IngressRuleValue {
474
+ HTTP : & v1beta1.HTTPIngressRuleValue {
475
+ Paths : []v1beta1.HTTPIngressPath {
476
+ {
477
+ Path : "/" ,
478
+ Backend : v1beta1.IngressBackend {
479
+ ServiceName : "foo-service" ,
480
+ ServicePort : intstr.IntOrString {IntVal : 80 , StrVal : "80" },
481
+ },
482
+ },
483
+ },
484
+ },
485
+ },
486
+ },
487
+ },
488
+ },
489
+ }, & v1beta1.Ingress {
490
+ ObjectMeta : v1.ObjectMeta {
491
+ Name : "foo-name" ,
492
+ Namespace : "bar-namespace" ,
493
+ Annotations : map [string ]string {
494
+ IngressAnnotation : IngressAnnotationValue ,
495
+ "bool.service.tyk.io/use-keyless" : "true" ,
496
+ },
497
+ },
498
+ Spec : v1beta1.IngressSpec {
499
+ Rules : []v1beta1.IngressRule {
500
+ {
501
+ Host : "foo.com" ,
502
+ IngressRuleValue : v1beta1.IngressRuleValue {
503
+ HTTP : & v1beta1.HTTPIngressRuleValue {
504
+ Paths : []v1beta1.HTTPIngressPath {
505
+ {
506
+ Path : "/" ,
507
+ Backend : v1beta1.IngressBackend {
508
+ ServiceName : "foo-service" ,
509
+ ServicePort : intstr.IntOrString {IntVal : 80 , StrVal : "80" },
510
+ },
511
+ },
512
+ },
513
+ },
514
+ },
515
+ },
516
+ },
517
+ },
518
+ },
466
519
},
467
520
}
468
521
469
522
func TestIngressChanged (t * testing.T ) {
470
523
524
+ t .Parallel ()
471
525
x := NewController ()
472
526
473
- for _ , tt := range ingTests {
474
- t .Run (tt .name , func (t * testing.T ) {
475
- changed := x .ingressChanged (tt .in , tt .out )
527
+ for name , tc := range ingTests {
528
+ name , tc := name , tc
529
+ t .Run (name , func (t * testing.T ) {
530
+ changed := x .ingressChanged (tc .in , tc .out )
476
531
if ! changed {
477
- t .Errorf ("Wanted change but none detected for: %s" , tt . name )
532
+ t .Errorf ("Wanted change but none detected for: %s" , name )
478
533
}
479
534
})
480
535
}
0 commit comments