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

Function newSingleNodeWithVMServer

pkg/api/grouped_cluster_test.go:242–287  ·  view source on GitHub ↗

newSingleNodeWithVMServer returns a test server that serves one node and one QEMU VM with the given vmID and name under /cluster/resources.

(ticket, nodeName string, vmID int, vmName, vmStatus string)

Source from the content-addressed store, hash-verified

240// newSingleNodeWithVMServer returns a test server that serves one node and one
241// QEMU VM with the given vmID and name under /cluster/resources.
242func newSingleNodeWithVMServer(ticket, nodeName string, vmID int, vmName, vmStatus string) *httptest.Server {
243 return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
244 w.Header().Set("Content-Type", "application/json")
245 switch r.URL.Path {
246 case testAPITicketPath:
247 _ = json.NewEncoder(w).Encode(map[string]interface{}{
248 "data": map[string]interface{}{
249 "ticket": ticket, "CSRFPreventionToken": "csrf",
250 },
251 })
252 case testAPIClusterResourcesPath:
253 _ = json.NewEncoder(w).Encode(map[string]interface{}{
254 "data": []interface{}{
255 map[string]interface{}{
256 "type": "node", "node": nodeName,
257 "cpu": 0.1, "maxcpu": 4,
258 "mem": 1024.0, "maxmem": 2048.0,
259 "disk": 1024.0, "maxdisk": 2048.0,
260 "uptime": 100,
261 },
262 map[string]interface{}{
263 "type": "qemu", "node": nodeName,
264 "vmid": vmID, "name": vmName, "status": vmStatus,
265 },
266 },
267 })
268 case testAPIClusterStatusPath:
269 _ = json.NewEncoder(w).Encode(map[string]interface{}{
270 "data": []interface{}{
271 map[string]interface{}{
272 "id": "node/" + nodeName, "name": nodeName,
273 "type": "node", "online": 1,
274 },
275 },
276 })
277 case testAPINodesPath:
278 _ = json.NewEncoder(w).Encode(map[string]interface{}{
279 "data": []interface{}{
280 map[string]interface{}{"node": nodeName, "status": "online"},
281 },
282 })
283 default:
284 w.WriteHeader(http.StatusNotFound)
285 }
286 }))
287}
288
289func TestFindVMByIDInGroup_Unique(t *testing.T) {
290 s1 := newSingleNodeWithVMServer("t1", "pve1", 100, "web", "running")

Calls 2

HeaderMethod · 0.80
SetMethod · 0.65

Tested by

no test coverage detected