test: add real fixture coverage for HPE AHS parser
This commit is contained in:
@@ -4,6 +4,8 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.mchus.pro/mchus/logpile/internal/parser"
|
"git.mchus.pro/mchus/logpile/internal/parser"
|
||||||
@@ -114,6 +116,49 @@ func TestParseAHSInventory(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestParseExampleAHS(t *testing.T) {
|
||||||
|
path := filepath.Join("..", "..", "..", "..", "example", "HPE_CZ2D1X0GS3_20260330.ahs")
|
||||||
|
content, err := os.ReadFile(path)
|
||||||
|
if err != nil {
|
||||||
|
t.Skipf("example fixture unavailable: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
p := &Parser{}
|
||||||
|
result, err := p.Parse([]parser.ExtractedFile{{
|
||||||
|
Path: filepath.Base(path),
|
||||||
|
Content: content,
|
||||||
|
}})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("parse example failed: %v", err)
|
||||||
|
}
|
||||||
|
if result.Hardware == nil {
|
||||||
|
t.Fatalf("expected hardware section")
|
||||||
|
}
|
||||||
|
|
||||||
|
board := result.Hardware.BoardInfo
|
||||||
|
if board.ProductName != "ProLiant DL380 Gen11" {
|
||||||
|
t.Fatalf("unexpected board product: %q", board.ProductName)
|
||||||
|
}
|
||||||
|
if board.SerialNumber != "CZ2D1X0GS3" {
|
||||||
|
t.Fatalf("unexpected board serial: %q", board.SerialNumber)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(result.Hardware.Storage) < 2 {
|
||||||
|
t.Fatalf("expected at least two drives, got %d", len(result.Hardware.Storage))
|
||||||
|
}
|
||||||
|
|
||||||
|
foundController := false
|
||||||
|
for _, device := range result.Hardware.Devices {
|
||||||
|
if device.Model == "HPE MR408i-o Gen11" && device.SerialNumber == "PXSFQ0BBIJY3B3" {
|
||||||
|
foundController = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !foundController {
|
||||||
|
t.Fatalf("expected MR408i-o controller in canonical devices")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type ahsTestEntry struct {
|
type ahsTestEntry struct {
|
||||||
Name string
|
Name string
|
||||||
Payload []byte
|
Payload []byte
|
||||||
|
|||||||
Reference in New Issue
Block a user