40 lines
1.3 KiB
Go
40 lines
1.3 KiB
Go
package server
|
|
|
|
import "testing"
|
|
|
|
func TestCollectExistingTunnelKeys(t *testing.T) {
|
|
labels := map[string]string{
|
|
"traefik.enable": "true",
|
|
"traefik.http.routers.tunnel-king73-taylor-co-com-router.rule": "Host(`king73.taylor-co.com`)",
|
|
"traefik.http.routers.tunnel-king73-taylor-co-com-router.entrypoints": "websecure",
|
|
"traefik.http.services.tunnel-king73-taylor-co-com-service.loadbalancer.server.port": "10007",
|
|
"traefik.http.middlewares.tunnel-king73-taylor-co-com-auth.basicauth.users": "user:hash",
|
|
}
|
|
|
|
tunnelKeys, authKeys := collectExistingTunnelKeys(labels)
|
|
|
|
if !tunnelKeys["king73-taylor-co-com"] {
|
|
t.Fatalf("expected tunnel key to be adopted")
|
|
}
|
|
if !authKeys["king73-taylor-co-com"] {
|
|
t.Fatalf("expected auth key to be adopted")
|
|
}
|
|
if tunnelKeys["not-a-tunnel"] {
|
|
t.Fatalf("unexpected non-tunnel key")
|
|
}
|
|
}
|
|
|
|
func TestTunnelKeyFromLabelRejectsInvalidLabels(t *testing.T) {
|
|
tests := []string{
|
|
"traefik.enable",
|
|
"traefik.http.routers.tunnel--router.rule",
|
|
"traefik.http.routers.not-tunnel-king73-router.rule",
|
|
}
|
|
|
|
for _, test := range tests {
|
|
if key, ok := tunnelKeyFromLabel(test, "traefik.http.routers.tunnel-", "-router."); ok {
|
|
t.Fatalf("expected %q to be rejected, got key %q", test, key)
|
|
}
|
|
}
|
|
}
|