test: cover unraid inventory integration
This commit is contained in:
@@ -0,0 +1,102 @@
|
|||||||
|
package unraid
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"git.mchus.pro/mchus/logpile/internal/parser"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestParseInventoryAndLogs(t *testing.T) {
|
||||||
|
files := []parser.ExtractedFile{
|
||||||
|
{Path: "diagnostics/system/motherboard.txt", Content: []byte(`Acme NAS Board
|
||||||
|
BIOS Information
|
||||||
|
Vendor: Acme
|
||||||
|
Version: 1.2.3
|
||||||
|
`)},
|
||||||
|
{Path: "diagnostics/system/meminfo.txt", Content: []byte(`Handle 0x0010, DMI type 17, 84 bytes
|
||||||
|
Memory Device
|
||||||
|
Size: 32 GB
|
||||||
|
Locator: DIMM_A1
|
||||||
|
Bank Locator: BANK 0
|
||||||
|
Type: DDR5
|
||||||
|
Speed: 5600 MT/s
|
||||||
|
Configured Memory Speed: 5200 MT/s
|
||||||
|
Manufacturer: Micron
|
||||||
|
Serial Number: MEM-1
|
||||||
|
Part Number: PN-1
|
||||||
|
Rank: 2
|
||||||
|
`)},
|
||||||
|
{Path: "diagnostics/system/ifconfig.txt", Content: []byte("eth0 UP 192.0.2.10/24\nlo UP 127.0.0.1\n")},
|
||||||
|
{Path: "diagnostics/system/ethtool.txt", Content: []byte(`Settings for eth0:
|
||||||
|
driver: mlx5_core
|
||||||
|
firmware-version: 1.0
|
||||||
|
bus-info: 0000:5e:00.0
|
||||||
|
Speed: 100000Mb/s
|
||||||
|
Link detected: yes
|
||||||
|
`)},
|
||||||
|
{Path: "diagnostics/system/lspci.txt", Content: []byte(`5e:00.0 Ethernet controller [0200]: Mellanox Technologies Network Adapter [15b3:101e]
|
||||||
|
3b:00.0 Non-Volatile memory controller [0108]: Acme NVMe [1234:5678]
|
||||||
|
`)},
|
||||||
|
{Path: "diagnostics/system/vars.txt", Content: []byte(`disks
|
||||||
|
(
|
||||||
|
[disk1] => Array
|
||||||
|
(
|
||||||
|
[device] => sda
|
||||||
|
[id] => WDC-1
|
||||||
|
[size] => 2097152
|
||||||
|
[temp] => 55
|
||||||
|
[fsType] => xfs
|
||||||
|
)
|
||||||
|
)
|
||||||
|
flashGUID
|
||||||
|
(
|
||||||
|
[flashGUID] => HOST-1
|
||||||
|
)
|
||||||
|
`)},
|
||||||
|
{Path: "diagnostics/logs/syslog.txt", Content: []byte("Feb 5 23:33:01 host kernel: fatal disk error\nFeb 5 23:33:02 host daemon: normal message\n")},
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := (&Parser{}).Parse(files)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Parse: %v", err)
|
||||||
|
}
|
||||||
|
if result.Hardware.BoardInfo.Manufacturer != "Acme" || result.Hardware.BoardInfo.ProductName != "Acme NAS Board" {
|
||||||
|
t.Fatalf("unexpected board: %+v", result.Hardware.BoardInfo)
|
||||||
|
}
|
||||||
|
if result.Hardware.BoardInfo.SerialNumber != "HOST-1" {
|
||||||
|
t.Fatalf("host serial = %q", result.Hardware.BoardInfo.SerialNumber)
|
||||||
|
}
|
||||||
|
if len(result.Hardware.Memory) != 1 || result.Hardware.Memory[0].Slot != "DIMM_A1" || result.Hardware.Memory[0].SizeMB != 32768 {
|
||||||
|
t.Fatalf("unexpected memory: %+v", result.Hardware.Memory)
|
||||||
|
}
|
||||||
|
if len(result.Hardware.NetworkAdapters) != 1 || result.Hardware.NetworkAdapters[0].Slot != "eth0" || result.Hardware.NetworkAdapters[0].Status != "ok" {
|
||||||
|
t.Fatalf("unexpected NICs: %+v", result.Hardware.NetworkAdapters)
|
||||||
|
}
|
||||||
|
if len(result.Hardware.PCIeDevices) != 2 {
|
||||||
|
t.Fatalf("unexpected PCIe devices: %+v", result.Hardware.PCIeDevices)
|
||||||
|
}
|
||||||
|
if len(result.Hardware.Storage) != 1 || result.Hardware.Storage[0].Slot != "disk1" || result.Hardware.Storage[0].SizeGB != 2 {
|
||||||
|
t.Fatalf("unexpected storage: %+v", result.Hardware.Storage)
|
||||||
|
}
|
||||||
|
if len(result.Sensors) != 1 || result.Sensors[0].Status != "warning" {
|
||||||
|
t.Fatalf("unexpected sensors: %+v", result.Sensors)
|
||||||
|
}
|
||||||
|
if len(result.Events) != 2 || result.Events[0].Severity != "critical" {
|
||||||
|
t.Fatalf("unexpected syslog events: %+v", result.Events)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUnraidParsingHelpers(t *testing.T) {
|
||||||
|
if got := firstWords("Mellanox Technologies Adapter", 2); got != "Mellanox Technologies" {
|
||||||
|
t.Fatalf("firstWords = %q", got)
|
||||||
|
}
|
||||||
|
if got := getTempStatus(60); got != "critical" {
|
||||||
|
t.Fatalf("temperature status = %q", got)
|
||||||
|
}
|
||||||
|
if got := getTempStatus(20); got != "ok" {
|
||||||
|
t.Fatalf("temperature status = %q", got)
|
||||||
|
}
|
||||||
|
if got := extractDiskSection(" [disk1] => Array\n (\n [id] => disk\n )", "disk1"); got == "" {
|
||||||
|
t.Fatal("expected disk section")
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user