97 lines
2.6 KiB
Go
97 lines
2.6 KiB
Go
package collector
|
|
|
|
import "testing"
|
|
|
|
func TestParseSASIrcuControllerIDs(t *testing.T) {
|
|
raw := `LSI Corporation SAS2 IR Configuration Utility.
|
|
Adapter List
|
|
==============
|
|
0 SAS2008(B2)
|
|
1 SAS2308_2(D1)
|
|
`
|
|
ids := parseSASIrcuControllerIDs(raw)
|
|
if len(ids) != 2 || ids[0] != 0 || ids[1] != 1 {
|
|
t.Fatalf("unexpected ids: %#v", ids)
|
|
}
|
|
}
|
|
|
|
func TestParseSASIrcuDisplay(t *testing.T) {
|
|
raw := `Device is a Hard disk
|
|
Enclosure # : 32
|
|
Slot # : 7
|
|
State : Onln
|
|
Size (in MB)/(in sectors) : 953869/1953525168
|
|
Model Number : ST1000NM0033
|
|
Serial No : Z1D12345
|
|
Protocol : SAS
|
|
Drive Type : HDD
|
|
|
|
Device is a Enclosure services device
|
|
Enclosure # : 32
|
|
`
|
|
drives := parseSASIrcuDisplay(raw)
|
|
if len(drives) != 1 {
|
|
t.Fatalf("expected 1 drive, got %d", len(drives))
|
|
}
|
|
d := drives[0]
|
|
if d.Slot == nil || *d.Slot != "32:7" {
|
|
t.Fatalf("slot: %v", d.Slot)
|
|
}
|
|
if d.SerialNumber == nil || *d.SerialNumber != "Z1D12345" {
|
|
t.Fatalf("serial: %v", d.SerialNumber)
|
|
}
|
|
if d.Interface == nil || *d.Interface != "SAS" {
|
|
t.Fatalf("interface: %v", d.Interface)
|
|
}
|
|
if d.Status == nil || *d.Status != "OK" {
|
|
t.Fatalf("status: %v", d.Status)
|
|
}
|
|
}
|
|
|
|
func TestParseArcconfPhysicalDrives(t *testing.T) {
|
|
raw := `Device #0
|
|
Reported Location : Channel 0, Device 3
|
|
Model : Micron_5300
|
|
Serial number : ARC12345
|
|
State : Online
|
|
Total Size : 894 GB
|
|
Transfer Speed : SATA 6.0Gb/s
|
|
SSD : Yes
|
|
`
|
|
drives := parseArcconfPhysicalDrives(raw)
|
|
if len(drives) != 1 {
|
|
t.Fatalf("expected 1 drive, got %d", len(drives))
|
|
}
|
|
d := drives[0]
|
|
if d.Type == nil || *d.Type != "SSD" {
|
|
t.Fatalf("type: %v", d.Type)
|
|
}
|
|
if d.Interface == nil || *d.Interface != "SATA" {
|
|
t.Fatalf("interface: %v", d.Interface)
|
|
}
|
|
if d.Status == nil || *d.Status != "OK" {
|
|
t.Fatalf("status: %v", d.Status)
|
|
}
|
|
}
|
|
|
|
func TestParseSSACLIPhysicalDrives(t *testing.T) {
|
|
raw := `physicaldrive 1I:1:1 (894 GB, SAS HDD, OK)
|
|
Serial Number: SSACLI001
|
|
Model: MB8000JVYZQ
|
|
|
|
physicaldrive 1I:1:2 (894 GB, SAS HDD, Failed)
|
|
Serial Number: SSACLI002
|
|
Model: MB8000JVYZQ
|
|
`
|
|
drives := parseSSACLIPhysicalDrives(raw)
|
|
if len(drives) != 2 {
|
|
t.Fatalf("expected 2 drives, got %d", len(drives))
|
|
}
|
|
if drives[0].Status == nil || *drives[0].Status != "OK" {
|
|
t.Fatalf("drive0 status: %v", drives[0].Status)
|
|
}
|
|
if drives[1].Status == nil || *drives[1].Status != "CRITICAL" {
|
|
t.Fatalf("drive1 status: %v", drives[1].Status)
|
|
}
|
|
}
|