@@ -4,61 +4,56 @@ import (
4
4
"testing"
5
5
6
6
"github.com/devfile/devworkspace-operator/apis/controller/v1alpha1"
7
+ "github.com/google/go-cmp/cmp"
7
8
"github.com/stretchr/testify/assert"
8
9
)
9
10
10
11
func TestGetRouteForEndpointAnnotations (t * testing.T ) {
11
12
tests := []struct {
12
13
name string
13
14
14
- routingSuffix string
15
- endpoint v1alpha1.Endpoint
16
- meta DevWorkspaceMetadata
17
- annotations map [string ]string
15
+ annotations map [string ]string
18
16
19
- expectedAnnotationsKeys [ ]string
17
+ expectedAnnotations map [ string ]string
20
18
}{
21
19
{
22
- name : "nil " ,
20
+ name : "Gets default OpenShift route annotation when annotations aren't defined " ,
23
21
24
22
annotations : nil ,
25
23
26
- expectedAnnotationsKeys : [ ]string {
27
- "controller.devfile.io/endpoint_name" ,
28
- "haproxy.router.openshift.io/rewrite-target" ,
24
+ expectedAnnotations : map [ string ]string {
25
+ "controller.devfile.io/endpoint_name" : "Endpoint" ,
26
+ "haproxy.router.openshift.io/rewrite-target" : "/" ,
29
27
},
30
28
},
31
29
{
32
- name : "empty" ,
30
+ name : "Gets default OpenShift route annotation when annotations are empty" ,
33
31
34
32
annotations : map [string ]string {},
35
33
36
- expectedAnnotationsKeys : [ ]string {
37
- "controller.devfile.io/endpoint_name" ,
38
- "haproxy.router.openshift.io/rewrite-target" ,
34
+ expectedAnnotations : map [ string ]string {
35
+ "controller.devfile.io/endpoint_name" : "Endpoint" ,
36
+ "haproxy.router.openshift.io/rewrite-target" : "/" ,
39
37
},
40
38
},
41
39
{
42
- name : "defined" ,
40
+ name : "Gets default OpenShift route annotation when annotations are defined" ,
43
41
44
42
annotations : map [string ]string {
45
43
"example.com/extra" : "val" ,
46
44
},
47
45
48
- expectedAnnotationsKeys : []string {
49
- "controller.devfile.io/endpoint_name" ,
50
- "example.com/extra" },
46
+ expectedAnnotations : map [string ]string {
47
+ "controller.devfile.io/endpoint_name" : "Endpoint" ,
48
+ "example.com/extra" : "val" ,
49
+ },
51
50
},
52
51
}
53
52
54
53
for _ , tt := range tests {
55
54
t .Run (tt .name , func (t * testing.T ) {
56
55
route := getRouteForEndpoint ("routingSuffix" , v1alpha1.Endpoint {Name : "Endpoint" }, DevWorkspaceMetadata {DevWorkspaceId : "WorkspaceTest" }, tt .annotations )
57
- for _ , expected := range tt .expectedAnnotationsKeys {
58
- _ , ok := route .Annotations [expected ]
59
- assert .True (t , ok , "Key %s does not exist" , expected )
60
- assert .Equal (t , len (tt .expectedAnnotationsKeys ), len (route .Annotations ))
61
- }
56
+ assert .Equal (t , tt .expectedAnnotations , route .Annotations , "Annotations should match: Diff: %s" , cmp .Diff (tt .expectedAnnotations , route .Annotations ))
62
57
})
63
58
}
64
59
}
@@ -67,59 +62,52 @@ func TestGetIngressForEndpointAnnotations(t *testing.T) {
67
62
tests := []struct {
68
63
name string
69
64
70
- routingSuffix string
71
- endpoint v1alpha1.Endpoint
72
- meta DevWorkspaceMetadata
73
- annotations map [string ]string
65
+ annotations map [string ]string
74
66
75
- expectedAnnotationsKeys [ ]string
67
+ expectedAnnotations map [ string ]string
76
68
}{
77
69
{
78
- name : "nil " ,
70
+ name : "Gets default Kubernetes ingress annotation when annotations aren't defined " ,
79
71
80
72
annotations : nil ,
81
73
82
- expectedAnnotationsKeys : [ ]string {
83
- "controller.devfile.io/endpoint_name" ,
84
- "kubernetes.io/ingress.class" ,
85
- "nginx.ingress.kubernetes.io/rewrite-target" ,
86
- "nginx.ingress.kubernetes.io/ssl-redirect" ,
74
+ expectedAnnotations : map [ string ]string {
75
+ "controller.devfile.io/endpoint_name" : "Endpoint" ,
76
+ "kubernetes.io/ingress.class" : "nginx" ,
77
+ "nginx.ingress.kubernetes.io/rewrite-target" : "/" ,
78
+ "nginx.ingress.kubernetes.io/ssl-redirect" : "false" ,
87
79
},
88
80
},
89
81
{
90
- name : "empty" ,
82
+ name : "Gets default Kubernetes ingress annotation when annotations are empty" ,
91
83
92
84
annotations : map [string ]string {},
93
85
94
- expectedAnnotationsKeys : [ ]string {
95
- "controller.devfile.io/endpoint_name" ,
96
- "kubernetes.io/ingress.class" ,
97
- "nginx.ingress.kubernetes.io/rewrite-target" ,
98
- "nginx.ingress.kubernetes.io/ssl-redirect" ,
86
+ expectedAnnotations : map [ string ]string {
87
+ "controller.devfile.io/endpoint_name" : "Endpoint" ,
88
+ "kubernetes.io/ingress.class" : "nginx" ,
89
+ "nginx.ingress.kubernetes.io/rewrite-target" : "/" ,
90
+ "nginx.ingress.kubernetes.io/ssl-redirect" : "false" ,
99
91
},
100
92
},
101
93
{
102
- name : "defined" ,
94
+ name : "Gets default Kubernetes ingress annotation when annotations are defined" ,
103
95
104
96
annotations : map [string ]string {
105
97
"kubernetes.io/ingress.class" : "traefik" ,
106
98
},
107
99
108
- expectedAnnotationsKeys : [ ]string {
109
- "controller.devfile.io/endpoint_name" ,
110
- "kubernetes.io/ingress.class" ,
100
+ expectedAnnotations : map [ string ]string {
101
+ "controller.devfile.io/endpoint_name" : "Endpoint" ,
102
+ "kubernetes.io/ingress.class" : "traefik" ,
111
103
},
112
104
},
113
105
}
114
106
115
107
for _ , tt := range tests {
116
108
t .Run (tt .name , func (t * testing.T ) {
117
109
ingress := getIngressForEndpoint ("routingSuffix" , v1alpha1.Endpoint {Name : "Endpoint" }, DevWorkspaceMetadata {DevWorkspaceId : "WorkspaceTest" }, tt .annotations )
118
- for _ , expected := range tt .expectedAnnotationsKeys {
119
- _ , ok := ingress .Annotations [expected ]
120
- assert .True (t , ok , "Key %s does not exist" , expected )
121
- assert .Equal (t , len (tt .expectedAnnotationsKeys ), len (ingress .Annotations ))
122
- }
110
+ assert .Equal (t , tt .expectedAnnotations , ingress .Annotations , "Annotations should match: Diff: %s" , cmp .Diff (tt .expectedAnnotations , ingress .Annotations ))
123
111
})
124
112
}
125
113
}
0 commit comments