From 3dba961abf25d47f4fc14de3350608701a237566 Mon Sep 17 00:00:00 2001 From: rcourtman Date: Tue, 2 Dec 2025 01:05:48 +0000 Subject: [PATCH] test: Add permanent failure test for ClusterClient.GetNodes Tests the error logging path when all endpoints fail with auth error (83.3% to 91.7% coverage). --- pkg/proxmox/cluster_client_test.go | 31 ++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/pkg/proxmox/cluster_client_test.go b/pkg/proxmox/cluster_client_test.go index 88936d3..62084f0 100644 --- a/pkg/proxmox/cluster_client_test.go +++ b/pkg/proxmox/cluster_client_test.go @@ -327,3 +327,34 @@ func TestIsAuthError(t *testing.T) { }) } } + +func TestClusterClient_GetNodes_PermanentFailure(t *testing.T) { + // Server that always returns auth error - not retryable + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusUnauthorized) + fmt.Fprint(w, `{"data":null,"errors":{"username":"invalid credentials"}}`) + })) + defer server.Close() + + cfg := ClientConfig{ + Host: server.URL, + TokenName: "invalid@pve!token", + TokenValue: "badvalue", + VerifySSL: false, + Timeout: 2 * time.Second, + } + + cc := NewClusterClient("test-cluster", cfg, []string{server.URL}) + + ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) + defer cancel() + + nodes, err := cc.GetNodes(ctx) + if err == nil { + t.Fatal("expected GetNodes to fail with auth error, got nil") + } + if nodes != nil { + t.Errorf("expected nil nodes on error, got %v", nodes) + } +}