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") + } +}