功能:完善云管助手与GPU故障恢复核对

This commit is contained in:
songyiming committed 2026-11-13 19:08:40 +08:00
1 parent b6026f9759
commit 9f7b01e4db
42 files changed
+3576 -120

No files matched your search

@@ -0,0 +1,38 @@
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(`<root status_code="200"><hostname>desktop-test</hostname></root>`))
}))
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 != ""
}