test: cover IPMI, PSU, and SAT formatting

This commit is contained in:
2026-09-12 16:36:07 +03:00
parent 9da6dac1bd
commit cfef94870f
6 changed files with 309 additions and 2 deletions
+43
View File
@@ -133,3 +133,46 @@ func TestMergePSUSDRAppendsPSUMissingFromFRU(t *testing.T) {
t.Fatalf("PSUs=%#v, want FRU PSU0 plus synthesized PSU1", got)
}
}
func TestParseFRUFiltersNonPSUAndNormalizesSlots(t *testing.T) {
psus := parseFRU(`
FRU Device Description : Builtin FRU Device (ID 0)
Board Mfg : Example Systems
FRU Device Description : PSU 2 (ID 12)
Board Product : Server PSU 1600W
Board Mfg : Acme Power
Board Serial : PS2-SERIAL
Board Part Number : ACME-1600
Board Extra : 1.4
FRU Device Description : Power Supply Bay 3 (ID 13)
Product Name : Redundant 800W
Product Manufacturer : Acme Power
Product Serial : PS3-SERIAL
`)
if len(psus) != 2 {
t.Fatalf("PSUs = %#v, want two PSU FRUs", psus)
}
if psus[0].Slot == nil || *psus[0].Slot != "1" || psus[0].Model == nil || *psus[0].Model != "Server PSU 1600W" ||
psus[0].WattageW == nil || *psus[0].WattageW != 1600 || psus[0].Status == nil || *psus[0].Status != statusOK {
t.Fatalf("first PSU = %#v", psus[0])
}
if psus[1].Slot == nil || *psus[1].Slot != "2" || psus[1].SerialNumber == nil || *psus[1].SerialNumber != "PS3-SERIAL" {
t.Fatalf("second PSU = %#v", psus[1])
}
}
func TestPSUNumericParsersRejectInvalidReadings(t *testing.T) {
for _, raw := range []string{"", "na", "0", "-1", "6001", "not-a-number"} {
if got := parseBoundedFloat(raw, 6000); got != nil {
t.Errorf("parseBoundedFloat(%q) = %v, want nil", raw, got)
}
}
if got := parseBoundedFloat("1200 Watts", 6000); got == nil || *got != 1200 {
t.Fatalf("parseBoundedFloat valid value = %v", got)
}
for raw, want := range map[string]int{"PSU 800W": 800, "1200W PLATINUM": 1200, "no wattage": 0, "6000W": 0} {
if got := parseWattage(raw); got != want {
t.Errorf("parseWattage(%q) = %d, want %d", raw, got, want)
}
}
}