sync file-type support across upload/convert and fix collected_at timezone handling

This commit is contained in:
2026-02-28 23:27:49 +03:00
parent 736b77f055
commit 4940cd9645
20 changed files with 931 additions and 49 deletions

View File

@@ -60,6 +60,108 @@ func TestApplyArchiveSourceMetadata_InferCollectedAtFromEvents(t *testing.T) {
}
}
func TestApplyArchiveSourceMetadata_InferCollectedAtFromFilename(t *testing.T) {
result := &models.AnalysisResult{
Filename: "dump_23E100203_20260228-0428.tar.gz",
}
applyArchiveSourceMetadata(result)
// 2026-02-28 04:28 in Europe/Moscow => 2026-02-28 01:28 UTC
want := time.Date(2026, 2, 28, 1, 28, 0, 0, time.UTC)
if !result.CollectedAt.Equal(want) {
t.Fatalf("expected collected_at from filename: got %s want %s", result.CollectedAt, want)
}
}
func TestApplyArchiveSourceMetadata_IgnoresSyntheticComponentNowEvents(t *testing.T) {
realTs := time.Date(2026, 2, 28, 4, 18, 18, 217225000, time.FixedZone("UTC+8", 8*3600))
syntheticNow := time.Date(2026, 3, 5, 10, 0, 0, 0, time.UTC)
result := &models.AnalysisResult{
Events: []models.Event{
{
Timestamp: realTs,
Source: "spx_restservice_ext",
SensorType:"syslog",
EventType: "System Log",
},
{
Timestamp: syntheticNow,
Source: "Fan",
SensorType: "fan",
EventType: "Fan Status",
},
},
}
applyArchiveSourceMetadata(result)
if !result.CollectedAt.Equal(realTs.UTC()) {
t.Fatalf("expected collected_at from real log timestamp: got %s want %s", result.CollectedAt, realTs.UTC())
}
}
func TestInferRawExportCollectedAt_PrefersResultCollectedAt(t *testing.T) {
expected := time.Date(2026, 2, 25, 8, 0, 0, 0, time.UTC)
result := &models.AnalysisResult{CollectedAt: expected}
pkg := &RawExportPackage{
ExportedAt: time.Date(2026, 2, 25, 9, 59, 41, 0, time.UTC),
Source: RawExportSource{
CollectLogs: []string{
"2026-02-25T09:00:00Z step1",
"2026-02-25T09:10:00Z step2",
},
},
}
got := inferRawExportCollectedAt(result, pkg)
if !got.Equal(expected) {
t.Fatalf("expected collected_at from result: got %s want %s", got, expected)
}
}
func TestInferRawExportCollectedAt_UsesCollectLogsThenExportedAt(t *testing.T) {
hintTs := time.Date(2026, 2, 25, 9, 58, 5, 912975300, time.UTC)
pkgWithLogs := &RawExportPackage{
ExportedAt: time.Date(2026, 2, 25, 9, 59, 41, 0, time.UTC),
CollectedAtHint: hintTs,
Source: RawExportSource{
CollectLogs: []string{
"2026-02-25T09:10:13.7442032Z started",
"2026-02-25T09:31:00.5077486Z finished",
},
},
}
got := inferRawExportCollectedAt(&models.AnalysisResult{}, pkgWithLogs)
if !got.Equal(hintTs) {
t.Fatalf("expected collected_at from parser_fields hint: got %s want %s", got, hintTs)
}
pkgFromLogs := &RawExportPackage{
ExportedAt: time.Date(2026, 2, 25, 9, 59, 41, 0, time.UTC),
Source: RawExportSource{
CollectLogs: []string{
"2026-02-25T09:10:13.7442032Z started",
"2026-02-25T09:31:00.5077486Z finished",
},
},
}
got = inferRawExportCollectedAt(&models.AnalysisResult{}, pkgFromLogs)
wantFromLogs := time.Date(2026, 2, 25, 9, 31, 0, 507748600, time.UTC)
if !got.Equal(wantFromLogs) {
t.Fatalf("expected collected_at from collect logs: got %s want %s", got, wantFromLogs)
}
pkgWithoutLogs := &RawExportPackage{
ExportedAt: time.Date(2026, 2, 25, 9, 59, 41, 479023400, time.UTC),
}
got = inferRawExportCollectedAt(&models.AnalysisResult{}, pkgWithoutLogs)
wantFromExportedAt := time.Date(2026, 2, 25, 9, 59, 41, 479023400, time.UTC)
if !got.Equal(wantFromExportedAt) {
t.Fatalf("expected collected_at from exported_at: got %s want %s", got, wantFromExportedAt)
}
}
func TestApplyCollectSourceMetadata(t *testing.T) {
req := CollectRequest{
Host: "bmc-api.local",
@@ -106,6 +208,32 @@ func TestApplyCollectSourceMetadata(t *testing.T) {
}
}
func TestApplyCollectSourceMetadata_PreservesCollectedAtAndTimezone(t *testing.T) {
req := CollectRequest{
Host: "bmc-api.local",
Protocol: "redfish",
Port: 443,
Username: "admin",
AuthType: "password",
Password: "super-secret",
TLSMode: "strict",
}
collectedAt := time.Date(2026, 2, 28, 4, 18, 18, 0, time.FixedZone("UTC+8", 8*3600))
result := &models.AnalysisResult{
CollectedAt: collectedAt,
SourceTimezone: "+08:00",
}
applyCollectSourceMetadata(result, req)
if !result.CollectedAt.Equal(collectedAt) {
t.Fatalf("expected collected_at to be preserved: got %s want %s", result.CollectedAt, collectedAt)
}
if result.SourceTimezone != "+08:00" {
t.Fatalf("expected source_timezone to be preserved, got %q", result.SourceTimezone)
}
}
func TestStatusAndConfigExposeSourceMetadata(t *testing.T) {
s := &Server{}
s.SetDetectedVendor("nvidia")