export: align reanimator contract v2.7
This commit is contained in:
@@ -1,101 +1,35 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"archive/zip"
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.mchus.pro/mchus/logpile/internal/models"
|
||||
)
|
||||
|
||||
func TestCollectLogTimeBounds(t *testing.T) {
|
||||
lines := []string{
|
||||
"2026-02-28T13:10:13.7442032Z Задача поставлена в очередь",
|
||||
"not-a-timestamp line",
|
||||
"2026-02-28T13:31:00.5077486Z Сбор завершен",
|
||||
}
|
||||
|
||||
startedAt, finishedAt, ok := collectLogTimeBounds(lines)
|
||||
if !ok {
|
||||
t.Fatalf("expected bounds to be parsed")
|
||||
}
|
||||
if got := formatRawExportDuration(finishedAt.Sub(startedAt)); got != "20m47s" {
|
||||
t.Fatalf("unexpected duration: %s", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildHumanReadableCollectionLog_IncludesDurationHeader(t *testing.T) {
|
||||
pkg := &RawExportPackage{
|
||||
Format: rawExportFormatV1,
|
||||
Source: RawExportSource{
|
||||
Kind: "live_redfish",
|
||||
CollectLogs: []string{
|
||||
"2026-02-28T13:10:13.7442032Z Redfish: подключение к BMC...",
|
||||
"2026-02-28T13:31:00.5077486Z Сбор завершен",
|
||||
func TestBuildParserFieldSummary_MirrorsBoardInfoToTopLevel(t *testing.T) {
|
||||
result := &models.AnalysisResult{
|
||||
Hardware: &models.HardwareConfig{
|
||||
BoardInfo: models.BoardInfo{
|
||||
Manufacturer: "Supermicro",
|
||||
ProductName: "SYS-821GE-TNHR",
|
||||
SerialNumber: "A514359X5C08846",
|
||||
PartNumber: "SYS-821GE-TNHR",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
logText := buildHumanReadableCollectionLog(pkg, nil, "LOGPile test")
|
||||
for _, token := range []string{
|
||||
"Collection Started:",
|
||||
"Collection Finished:",
|
||||
"Collection Duration:",
|
||||
} {
|
||||
if !strings.Contains(logText, token) {
|
||||
t.Fatalf("expected %q in log header", token)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseRawExportBundle_ExtractsCollectedAtHintFromParserFields(t *testing.T) {
|
||||
pkg := &RawExportPackage{
|
||||
Format: rawExportFormatV1,
|
||||
ExportedAt: time.Date(2026, 2, 25, 9, 59, 41, 479023400, time.UTC),
|
||||
Source: RawExportSource{
|
||||
Kind: "live_redfish",
|
||||
},
|
||||
}
|
||||
pkgJSON, err := json.Marshal(pkg)
|
||||
if err != nil {
|
||||
t.Fatalf("marshal pkg: %v", err)
|
||||
}
|
||||
|
||||
parserFields := []byte(`{"collected_at":"2026-02-25T09:58:05.9129753Z"}`)
|
||||
|
||||
var buf bytes.Buffer
|
||||
zw := zip.NewWriter(&buf)
|
||||
|
||||
jf, err := zw.Create(rawExportBundlePackageFile)
|
||||
if err != nil {
|
||||
t.Fatalf("create package file: %v", err)
|
||||
}
|
||||
if _, err := jf.Write(pkgJSON); err != nil {
|
||||
t.Fatalf("write package file: %v", err)
|
||||
}
|
||||
|
||||
ff, err := zw.Create(rawExportBundleFieldsFile)
|
||||
if err != nil {
|
||||
t.Fatalf("create parser fields file: %v", err)
|
||||
}
|
||||
if _, err := ff.Write(parserFields); err != nil {
|
||||
t.Fatalf("write parser fields file: %v", err)
|
||||
}
|
||||
|
||||
if err := zw.Close(); err != nil {
|
||||
t.Fatalf("close zip writer: %v", err)
|
||||
}
|
||||
|
||||
gotPkg, ok, err := parseRawExportBundle(buf.Bytes())
|
||||
if err != nil {
|
||||
t.Fatalf("parse bundle: %v", err)
|
||||
}
|
||||
if !ok || gotPkg == nil {
|
||||
t.Fatalf("expected valid raw export bundle")
|
||||
}
|
||||
want := time.Date(2026, 2, 25, 9, 58, 5, 912975300, time.UTC)
|
||||
if !gotPkg.CollectedAtHint.Equal(want) {
|
||||
t.Fatalf("expected collected_at hint %s, got %s", want, gotPkg.CollectedAtHint)
|
||||
got := buildParserFieldSummary(result)
|
||||
|
||||
if got["vendor"] != "Supermicro" {
|
||||
t.Fatalf("expected vendor mirror, got %v", got["vendor"])
|
||||
}
|
||||
if got["model"] != "SYS-821GE-TNHR" {
|
||||
t.Fatalf("expected model mirror, got %v", got["model"])
|
||||
}
|
||||
if got["serial"] != "A514359X5C08846" {
|
||||
t.Fatalf("expected serial mirror, got %v", got["serial"])
|
||||
}
|
||||
if got["part_number"] != "SYS-821GE-TNHR" {
|
||||
t.Fatalf("expected part_number mirror, got %v", got["part_number"])
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user