-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathcommon_test.go
More file actions
113 lines (91 loc) · 3.28 KB
/
common_test.go
File metadata and controls
113 lines (91 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package solvers
import (
"testing"
"github.com/devfile/devworkspace-operator/apis/controller/v1alpha1"
"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/assert"
)
func TestGetRouteForEndpointAnnotations(t *testing.T) {
tests := []struct {
name string
annotations map[string]string
expectedAnnotations map[string]string
}{
{
name: "Gets default OpenShift route annotation when annotations aren't defined",
annotations: nil,
expectedAnnotations: map[string]string{
"controller.devfile.io/endpoint_name": "Endpoint",
"haproxy.router.openshift.io/rewrite-target": "/",
},
},
{
name: "Gets default OpenShift route annotation when annotations are empty",
annotations: map[string]string{},
expectedAnnotations: map[string]string{
"controller.devfile.io/endpoint_name": "Endpoint",
"haproxy.router.openshift.io/rewrite-target": "/",
},
},
{
name: "Gets default OpenShift route annotation when annotations are defined",
annotations: map[string]string{
"example.com/extra": "val",
},
expectedAnnotations: map[string]string{
"controller.devfile.io/endpoint_name": "Endpoint",
"example.com/extra": "val",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
route := getRouteForEndpoint("routingSuffix", v1alpha1.Endpoint{Name: "Endpoint"}, DevWorkspaceMetadata{DevWorkspaceId: "WorkspaceTest"}, tt.annotations)
assert.Equal(t, tt.expectedAnnotations, route.Annotations, "Annotations should match: Diff: %s", cmp.Diff(tt.expectedAnnotations, route.Annotations))
})
}
}
func TestGetIngressForEndpointAnnotations(t *testing.T) {
tests := []struct {
name string
annotations map[string]string
expectedAnnotations map[string]string
}{
{
name: "Gets default Kubernetes ingress annotation when annotations aren't defined",
annotations: nil,
expectedAnnotations: map[string]string{
"controller.devfile.io/endpoint_name": "Endpoint",
"kubernetes.io/ingress.class": "nginx",
"nginx.ingress.kubernetes.io/rewrite-target": "/",
"nginx.ingress.kubernetes.io/ssl-redirect": "false",
},
},
{
name: "Gets default Kubernetes ingress annotation when annotations are empty",
annotations: map[string]string{},
expectedAnnotations: map[string]string{
"controller.devfile.io/endpoint_name": "Endpoint",
"kubernetes.io/ingress.class": "nginx",
"nginx.ingress.kubernetes.io/rewrite-target": "/",
"nginx.ingress.kubernetes.io/ssl-redirect": "false",
},
},
{
name: "Gets default Kubernetes ingress annotation when annotations are defined",
annotations: map[string]string{
"kubernetes.io/ingress.class": "traefik",
},
expectedAnnotations: map[string]string{
"controller.devfile.io/endpoint_name": "Endpoint",
"kubernetes.io/ingress.class": "traefik",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ingress := getIngressForEndpoint("routingSuffix", v1alpha1.Endpoint{Name: "Endpoint"}, DevWorkspaceMetadata{DevWorkspaceId: "WorkspaceTest"}, tt.annotations)
assert.Equal(t, tt.expectedAnnotations, ingress.Annotations, "Annotations should match: Diff: %s", cmp.Diff(tt.expectedAnnotations, ingress.Annotations))
})
}
}