package agent import ( "testing" "git.wntrmute.dev/mc/mcp/internal/registry" ) func TestListenerForMode(t *testing.T) { tests := []struct { mode string port int want string }{ {"l4", 8443, ":8443"}, {"l7", 443, ":443"}, {"l4", 9443, ":9443"}, } for _, tt := range tests { got := listenerForMode(tt.mode, tt.port) if got != tt.want { t.Errorf("listenerForMode(%q, %d) = %q, want %q", tt.mode, tt.port, got, tt.want) } } } func TestNilProxyRouterIsNoop(t *testing.T) { var p *ProxyRouter // All methods should return nil on a nil ProxyRouter. if err := p.RegisterRoutes(nil, "svc", nil, nil); err != nil { t.Errorf("RegisterRoutes on nil: %v", err) } if err := p.RemoveRoutes(nil, "svc", nil); err != nil { t.Errorf("RemoveRoutes on nil: %v", err) } if err := p.Close(); err != nil { t.Errorf("Close on nil: %v", err) } } func TestRegisterRoutesSkipsZeroHostPort(t *testing.T) { // A nil ProxyRouter should be a no-op, so this tests the skip logic // indirectly. With a nil proxy, RegisterRoutes returns nil even // with routes that have zero host ports. var p *ProxyRouter routes := []registry.Route{ {Name: "rest", Port: 8443, Mode: "l4"}, } hostPorts := map[string]int{"rest": 0} if err := p.RegisterRoutes(nil, "svc", routes, hostPorts); err != nil { t.Errorf("RegisterRoutes: %v", err) } }