Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

test: Add JSON decode error test for Client.GetNodes

rcourtman5bbf7de1a3f1
diff --git a/pkg/proxmox/client_test.go b/pkg/proxmox/client_test.go
index d5e42ce274..b78a23a888 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")
+ }
+}