(t *testing.T)
| 70 | } |
| 71 | |
| 72 | func 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 { |
nothing calls this directly
no test coverage detected