Files
Pulse/pkg/proxmox/cluster_client_additional_api6_test.go
rcourtman 8399207f91 Isolate guest-agent test fixtures from recycled ports
Guest fences intentionally outlive a closed fixture listener and are
keyed by endpoint URL, so a test whose client used a fixture's raw
loopback URL inherited an earlier case's cooldown whenever the kernel
handed its server a recycled port. Its first read then came back
agent-cooldown instead of what the test expected. That failed rest-0
twice in a row on one pull request, and one in twelve local runs of
the guest-agent tests.

Single-server and per-case fixtures now use guestAgentFixtureEndpoint,
the package's existing per-case boundary, as the HTTP status and lock
evidence tests already do. Tests whose clients share fences across raw
endpoints by design, the alias and cluster tests and the older client
API tests, start from an empty guest registry instead. The capacity
tests keep raw endpoints: they seed protected work under them and
already reset the registry.

None of twenty fresh-process runs failed afterwards, and the package
passes with and without the race detector.
2026-10-24 00:50:38 +01:00

67 lines
1.9 KiB
Go

package proxmox
import (
"context"
"fmt"
"net/http"
"net/http/httptest"
"strings"
"testing"
"time"
)
func TestClusterClient_GetNodePendingUpdates_NoHealthyNodes(t *testing.T) {
cc := &ClusterClient{
name: "test",
endpoints: []string{"node1", "node2"},
nodeHealth: map[string]bool{"node1": false, "node2": false},
lastError: make(map[string]string),
lastHealthCheck: map[string]time.Time{
"node1": time.Now(),
"node2": time.Now(),
},
rateLimitUntil: make(map[string]time.Time),
}
updates, err := cc.GetNodePendingUpdates(context.Background(), "node1")
if err == nil {
t.Fatal("expected unavailable cluster error to remain distinguishable from a confirmed empty update list")
}
if len(updates) != 0 {
t.Fatalf("expected empty updates on no healthy nodes, got %+v", updates)
}
}
func TestClusterClient_GetVMAgentVersion_QemuGA(t *testing.T) {
isolateGuestAgentCapacity(t)
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Guest reads require fresh operation-lock evidence, independently of their payload fixture.
if strings.HasSuffix(r.URL.Path, "/config") {
fmt.Fprint(w, `{"data":{}}`)
return
}
w.Header().Set("Content-Type", "application/json")
if r.URL.Path == "/api2/json/nodes" {
fmt.Fprint(w, `{"data":[{"node":"node1","status":"online"}]}`)
return
}
if r.URL.Path == "/api2/json/nodes/node1/qemu/100/agent/info" {
fmt.Fprint(w, `{"data":{"result":{"qemu-ga":{"version":"7.2.0"}}}}`)
return
}
w.WriteHeader(http.StatusNotFound)
}))
defer server.Close()
cfg := ClientConfig{Host: server.URL, TokenName: "u@p!t", TokenValue: "v"}
cc := NewClusterClient("test", cfg, []string{server.URL}, nil)
version, err := cc.GetVMAgentVersion(context.Background(), "node1", 100)
if err != nil {
t.Fatalf("GetVMAgentVersion failed: %v", err)
}
if version != "7.2.0" {
t.Fatalf("unexpected version: %s", version)
}
}