-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy_test.go
More file actions
62 lines (59 loc) · 1.32 KB
/
deploy_test.go
File metadata and controls
62 lines (59 loc) · 1.32 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
package main
import (
"strings"
"testing"
)
func TestGenerateTraefikLabels(t *testing.T) {
tests := []struct {
name string
serviceName string
router RouterConfig
wantLabels []string
}{
{
name: "Simple Auth Host",
serviceName: "app",
router: RouterConfig{
Domain: "app.com",
Auth: true,
},
wantLabels: []string{
"traefik.enable=true",
"traefik.http.routers.app.rule=Host(`app.com`)",
"traefik.http.routers.app.middlewares=global-auth",
},
},
{
name: "Complex Legacy",
serviceName: "legacy",
router: RouterConfig{
Host: "old.com",
InternalPort: 3000,
PathPrefix: "/api",
StripPrefix: true,
},
wantLabels: []string{
"traefik.http.routers.legacy.rule=Host(`old.com`)",
"traefik.http.middlewares.legacy-strip.stripprefix.prefixes=/api",
"traefik.http.services.legacy.loadbalancer.server.port=3000",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := generateTraefikLabels(tt.serviceName, tt.router, "resolver")
for _, want := range tt.wantLabels {
found := false
for _, g := range got {
if strings.Contains(g, want) {
found = true
break
}
}
if !found {
t.Errorf("Missing expected label: %s. Got: %v", want, got)
}
}
})
}
}