MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / newStorageTestServer

Function newStorageTestServer

internal/cli/cli_integration_test.go:34–61  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

32}
33
34func newStorageTestServer(t *testing.T) *httptest.Server {
35 t.Helper()
36
37 return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
38 w.Header().Set("Content-Type", "application/json")
39
40 switch {
41 case r.URL.Path == "/api2/json/access/ticket":
42 _, _ = w.Write([]byte(authResponse))
43
44 case strings.HasSuffix(r.URL.Path, "/storage") && strings.Contains(r.URL.Path, "/nodes/"):
45 _, _ = w.Write([]byte(storageListResponse()))
46
47 case strings.Contains(r.URL.Path, "/storage/") && strings.HasSuffix(r.URL.Path, "/content"):
48 _, _ = w.Write([]byte(storageContentResponse()))
49
50 case r.URL.Path == "/api2/json/cluster/resources":
51 // Minimal cluster resources so getNodes works.
52 _, _ = w.Write([]byte(`{"data":[{"type":"node","node":"pve01","status":"online","id":"node/pve01"}]}`))
53
54 case r.URL.Path == "/api2/json/cluster/status":
55 _, _ = w.Write([]byte(`{"data":[{"type":"cluster","name":"pve","nodes":1}]}`))
56
57 default:
58 http.NotFound(w, r)
59 }
60 }))
61}
62
63func TestStorageListReturnsRows(t *testing.T) {
64 server := newStorageTestServer(t)

Calls 4

storageListResponseFunction · 0.85
storageContentResponseFunction · 0.85
HeaderMethod · 0.80
SetMethod · 0.65

Tested by

no test coverage detected