From fac03d3a52cc54582a3da7d5a644396818f3ce20 Mon Sep 17 00:00:00 2001 From: rcourtman Date: Tue, 2 Dec 2025 01:03:30 +0000 Subject: [PATCH] test: Add JSON decode error test for Client.GetNodes Tests the error path when server returns invalid JSON (87.5% to 100%). --- pkg/proxmox/client_test.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/pkg/proxmox/client_test.go b/pkg/proxmox/client_test.go index d5e42ce..b78a23a 100644 --- a/pkg/proxmox/client_test.go +++ b/pkg/proxmox/client_test.go @@ -1,10 +1,14 @@ package proxmox import ( + "context" "encoding/json" "fmt" "math" + "net/http" + "net/http/httptest" "testing" + "time" ) func TestDiskUnmarshalWearout(t *testing.T) { @@ -1252,3 +1256,32 @@ func TestGetMHzString(t *testing.T) { }) } } + +func TestGetNodes_InvalidJSON(t *testing.T) { + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + // Return invalid JSON that will cause decode error + fmt.Fprint(w, `{"data": [{"node": "test" invalid json}`) + })) + defer server.Close() + + cfg := ClientConfig{ + Host: server.URL, + TokenName: "test@pve!token", + TokenValue: "secret", + VerifySSL: false, + Timeout: 2 * time.Second, + } + + client, err := NewClient(cfg) + if err != nil { + t.Fatalf("NewClient failed: %v", err) + } + + ctx := context.Background() + _, err = client.GetNodes(ctx) + if err == nil { + t.Fatal("expected JSON decode error, got nil") + } +}