mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-10-23 20:25:56 +00:00
test(vmware): define local JSON response helper for request-shape test
The vmware test package defines writeJSON as a function-local closure, so the new request-shape test needs its own package-level helper. Change-source: pulse-maintainer
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user