package server import ( "context" "net" "net/http" "net/http/httptest" "net/url" "testing" ) func TestSunshineReadyAt(t *testing.T) { server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.URL.Path != "/serverinfo" { t.Fatalf("unexpected path %s", r.URL.Path) } w.Header().Set("Content-Type", "application/xml") _, _ = w.Write([]byte(`desktop-test`)) })) t.Cleanup(server.Close) host, port, ok := splitTestEndpoint(t, server.URL) if !ok || !sunshineReadyAt(context.Background(), host, port) { t.Fatal("expected Sunshine probe to pass") } if sunshineReadyAt(context.Background(), host, "1") { t.Fatal("unexpected Sunshine probe success on wrong port") } } func splitTestEndpoint(t *testing.T, raw string) (string, string, bool) { t.Helper() parsed, err := url.Parse(raw) if err != nil { return "", "", false } host, port, err := net.SplitHostPort(parsed.Host) return host, port, err == nil && host != "" && port != "" }