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

Function TestGetNodeDisks

pkg/api/node_disks_test.go:14–70  ·  view source on GitHub ↗

nolint:dupl // Test structure similarity is acceptable

(t *testing.T)

Source from the content-addressed store, hash-verified

12
13//nolint:dupl // Test structure similarity is acceptable
14func TestGetNodeDisks(t *testing.T) {
15 mockResponse := `{
16 "data": [
17 {
18 "devpath": "/dev/sda",
19 "health": "PASSED",
20 "model": "Samsung SSD 860",
21 "serial": "S4XBNF0M123456",
22 "size": 500107862016,
23 "type": "ssd",
24 "used": "partitions"
25 }
26 ]
27 }`
28
29 server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
30 if r.URL.Path == testAPITicketPath {
31 _, _ = w.Write([]byte(`{"data":{"ticket":"ticket","CSRFPreventionToken":"token","username":"user@pam"}}`))
32 return
33 }
34 if r.URL.Path != "/api2/json/nodes/pve1/disks/list" {
35 t.Errorf("Expected path /api2/json/nodes/pve1/disks/list, got %s", r.URL.Path)
36 }
37 _, _ = w.Write([]byte(mockResponse))
38 }))
39 defer server.Close()
40
41 mockConfig := &MockConfig{
42 Addr: server.URL,
43 User: "user",
44 Password: "password",
45 Realm: "pam",
46 Insecure: true,
47 }
48 // Important: Provide a NoOpCache to avoid nil pointer panic
49 client, err := NewClient(mockConfig, WithCache(&interfaces.NoOpCache{}))
50 if err != nil {
51 t.Fatalf("NewClient failed: %v", err)
52 }
53
54 disks, err := client.GetNodeDisks("pve1")
55 if err != nil {
56 t.Fatalf("GetNodeDisks failed: %v", err)
57 }
58
59 if len(disks) != 1 {
60 t.Fatalf("Expected 1 disk, got %d", len(disks))
61 }
62
63 if disks[0].Model != "Samsung SSD 860" {
64 t.Errorf("Expected model 'Samsung SSD 860', got '%s'", disks[0].Model)
65 }
66
67 if disks[0].Size != 500107862016 {
68 t.Errorf("Expected size 500107862016, got %d", disks[0].Size)
69 }
70}
71

Callers

nothing calls this directly

Calls 4

GetNodeDisksMethod · 0.95
NewClientFunction · 0.85
WithCacheFunction · 0.85
CloseMethod · 0.65

Tested by

no test coverage detected