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

Function TestStorageContentListJSONShape

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

Source from the content-addressed store, hash-verified

136}
137
138func TestStorageContentListJSONShape(t *testing.T) {
139 server := newStorageTestServer(t)
140 defer server.Close()
141
142 client := newTestClient(t, server.URL)
143
144 items, err := client.GetStorageContent("pve01", "local", "iso")
145 if err != nil {
146 t.Fatalf("GetStorageContent returned error: %v", err)
147 }
148
149 rows := make([]storageContentRow, 0, len(items))
150 for _, item := range items {
151 name := item.VolID
152 if idx := strings.LastIndex(name, "/"); idx >= 0 {
153 name = name[idx+1:]
154 }
155
156 rows = append(rows, storageContentRow{
157 VolID: item.VolID,
158 Name: name,
159 Type: item.Content,
160 Size: item.Size,
161 CTime: item.CreatedAt.Unix(),
162 VMID: item.VMID,
163 })
164 }
165
166 data, err := json.Marshal(rows)
167 if err != nil {
168 t.Fatalf("json.Marshal: %v", err)
169 }
170
171 var decoded []storageContentRow
172 if err := json.Unmarshal(data, &decoded); err != nil {
173 t.Fatalf("output is not valid JSON array of content rows: %v\noutput: %s", err, data)
174 }
175
176 if len(decoded) != len(rows) {
177 t.Errorf("decoded %d rows, want %d", len(decoded), len(rows))
178 }
179}

Callers

nothing calls this directly

Calls 4

newStorageTestServerFunction · 0.85
GetStorageContentMethod · 0.80
newTestClientFunction · 0.70
CloseMethod · 0.65

Tested by

no test coverage detected