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(vmware): define local JSON response helper for request-shape test

pulse-triage[bot]c978cc452c34
diff --git a/internal/vmware/client_vi_json_request_test.go b/internal/vmware/client_vi_json_request_test.go
index df70ea0ed5..01baa02a6d 100644
--- a/internal/vmware/client_vi_json_request_test.go
+++ b/internal/vmware/client_vi_json_request_test.go
@@ -2,6 +2,7 @@ package vmware
import (
"context"
+ "encoding/json"
"io"
"net/http"
"net/http/httptest"
@@ -10,6 +11,11 @@ import (
"time"
)
+func writeVIJSONResponse(w http.ResponseWriter, payload any) {
+ w.Header().Set("Content-Type", "application/json")
+ _ = json.NewEncoder(w).Encode(payload)
+}
+
// The vSphere VI JSON API documents a `_typeName` discriminator on request data
// objects. A bare ManagedObjectReference is accepted without one, but the
// composite argument objects (PerfQuerySpec, PerfMetricId, EventFilterSpec and
@@ -39,7 +45,7 @@ func TestQueryPerfRequestCarriesTypeNameDiscriminators(t *testing.T) {
mux := http.NewServeMux()
mux.HandleFunc("/sdk/vim25/9.0.0.0/PerformanceManager/PerformanceManager/QueryPerf", func(w http.ResponseWriter, r *http.Request) {
raw, _ = io.ReadAll(r.Body)
- writeJSON(w, []map[string]any{})
+ writeVIJSONResponse(w, []map[string]any{})
})
client, closeServer := newVIJSONRequestClient(t, mux)
defer closeServer()
@@ -75,7 +81,7 @@ func TestQueryEventsRequestCarriesTypeNameDiscriminators(t *testing.T) {
mux := http.NewServeMux()
mux.HandleFunc("/sdk/vim25/9.0.0.0/EventManager/EventManager/QueryEvents", func(w http.ResponseWriter, r *http.Request) {
raw, _ = io.ReadAll(r.Body)
- writeJSON(w, []map[string]any{})
+ writeVIJSONResponse(w, []map[string]any{})
})
client, closeServer := newVIJSONRequestClient(t, mux)
defer closeServer()