package webui import "testing" func TestParseFRUOutputExtraFields(t *testing.T) { // Realistic ipmitool fru print output: repeated " Extra" lines // (one per custom field) must resolve to sequential indices per the // vendor FRU doc (Chassis Extra starts at 2, Board Extra at 5, Product // Extra at 7), not all collapse onto the same index. out := ` Product Manufacturer : Inspur Product Name : NF5280M6 Product Part Number : PN123 Product Version : 1.0 Product Serial : SN123 Product Asset Tag : ASSET01 Product Extra : custom-p1 Board Mfg : Inspur Board Product : BoardX Board Serial : BSN1 Board Part Number : BPN1 Board Extra : custom-b1 Board Extra : custom-b2 Board Extra : custom-b3 Chassis Part Number : CPN1 Chassis Serial : CSN1 Chassis Extra : front-half Chassis Extra : back-half ` fields := parseFRUOutput(out) byName := map[string][]fruField{} for _, f := range fields { byName[f.Name] = append(byName[f.Name], f) } assertMeta := func(name string, occurrence int, wantArea string, wantIndex int) { t.Helper() list := byName[name] if occurrence >= len(list) { t.Fatalf("expected occurrence %d of %q, got %d entries", occurrence, name, len(list)) } f := list[occurrence] if f.Area != wantArea || f.Index != wantIndex { t.Errorf("%s[%d] = area:%q index:%d, want area:%q index:%d", name, occurrence, f.Area, f.Index, wantArea, wantIndex) } if !f.Editable { t.Errorf("%s[%d] expected editable", name, occurrence) } } assertMeta("Product Asset Tag", 0, "p", 5) assertMeta("Product Extra", 0, "p", 7) assertMeta("Board Extra", 0, "b", 5) assertMeta("Board Extra", 1, "b", 6) assertMeta("Board Extra", 2, "b", 7) assertMeta("Chassis Extra", 0, "c", 2) assertMeta("Chassis Extra", 1, "c", 3) }