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

Function TestGetNodeDiskSmart

pkg/api/node_disks_test.go:72–136  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

70}
71
72func TestGetNodeDiskSmart(t *testing.T) {
73 mockResponse := `{
74 "data": {
75 "health": "PASSED",
76 "type": "ssd",
77 "text": "Self-test passed",
78 "attributes": [
79 {
80 "id": 5,
81 "name": "Reallocated_Sector_Ct",
82 "value": 100,
83 "worst": 100,
84 "thresh": 10,
85 "fail": false,
86 "raw": "0"
87 }
88 ]
89 }
90 }`
91
92 server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
93 if r.URL.Path == testAPITicketPath {
94 _, _ = w.Write([]byte(`{"data":{"ticket":"ticket","CSRFPreventionToken":"token","username":"user@pam"}}`))
95 return
96 }
97 expectedPath := "/api2/json/nodes/pve1/disks/smart"
98 if r.URL.Path != expectedPath {
99 t.Errorf("Expected path %s, got %s", expectedPath, r.URL.Path)
100 }
101 if r.URL.Query().Get("disk") != "/dev/sda" {
102 t.Errorf("Expected disk query param /dev/sda, got %s", r.URL.Query().Get("disk"))
103 }
104 _, _ = w.Write([]byte(mockResponse))
105 }))
106 defer server.Close()
107
108 mockConfig := &MockConfig{
109 Addr: server.URL,
110 User: "user",
111 Password: "password",
112 Realm: "pam",
113 Insecure: true,
114 }
115 client, err := NewClient(mockConfig, WithCache(&interfaces.NoOpCache{}))
116 if err != nil {
117 t.Fatalf("NewClient failed: %v", err)
118 }
119
120 smart, err := client.GetNodeDiskSmart("pve1", "/dev/sda")
121 if err != nil {
122 t.Fatalf("GetNodeDiskSmart failed: %v", err)
123 }
124
125 if smart.Health != "PASSED" {
126 t.Errorf("Expected health PASSED, got %s", smart.Health)
127 }
128
129 if len(smart.Attributes) != 1 {

Callers

nothing calls this directly

Calls 5

GetNodeDiskSmartMethod · 0.95
NewClientFunction · 0.85
WithCacheFunction · 0.85
GetMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected