package client import ( "context" "net" "testing" ) func TestCheckLocal(t *testing.T) { listener, err := net.Listen("tcp", "127.0.0.1:0") if err != nil { t.Fatal(err) } defer listener.Close() go func() { for { conn, err := listener.Accept() if err != nil { return } conn.Close() } }() ctx := context.Background() if up, detail := CheckLocal(ctx, listener.Addr().String()); !up { t.Errorf("listener should be up: %s", detail) } if up, _ := CheckLocal(ctx, "127.0.0.1:1"); up { t.Error("closed port should be down") } } func TestCheckSummary(t *testing.T) { results := []RouteCheck{ {LocalUp: true, PublicUp: true}, {LocalUp: false, PublicUp: true}, } if got := CheckSummary(results); got != "local 1/2 up ยท public 2/2 up" { t.Errorf("summary = %q", got) } } func TestCheckRouteMissing(t *testing.T) { cfg := &Config{Routes: map[string]Route{}, Hostname: "abc.tunnel.example"} result := CheckRoute(context.Background(), cfg, "missing") if result.LocalUp || result.PublicUp || result.LocalError == "" { t.Errorf("missing route result: %+v", result) } }