Dump data is always historical. Parsers stamped undated events with time.Now() (Inspur component.log memory/fan status, IDL/H3C SEL with unparsable time, NVIDIA summary/bug-report, generic, XigmaNAS, Unraid, Redfish replay warnings), so an August dump opened in September showed DIMM warnings dated the day of analysis. - Events without a source time keep a zero timestamp. - Yearless syslog timestamps take the year from the collection time via parser.ParseYearlessInDefaultArchiveLocation; zero when unknown. - Archive/uploaded-snapshot collected_at is no longer defaulted to now; only live API collection uses the current time. ADL-070. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
76 lines
2.4 KiB
Go
76 lines
2.4 KiB
Go
package parser
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"git.mchus.pro/mchus/logpile/internal/models"
|
|
)
|
|
|
|
func TestAppendExtractionWarnings(t *testing.T) {
|
|
result := &models.AnalysisResult{
|
|
Events: make([]models.Event, 0),
|
|
}
|
|
|
|
files := []ExtractedFile{
|
|
{Path: "ok.log", Content: []byte("ok")},
|
|
{Path: "big.log", Truncated: true, TruncatedMessage: "file exceeded size limit and was truncated"},
|
|
}
|
|
|
|
appendExtractionWarnings(result, files)
|
|
|
|
if len(result.Events) != 1 {
|
|
t.Fatalf("expected 1 warning event, got %d", len(result.Events))
|
|
}
|
|
ev := result.Events[0]
|
|
if ev.Severity != models.SeverityWarning {
|
|
t.Fatalf("expected warning severity, got %q", ev.Severity)
|
|
}
|
|
if ev.EventType != "Analysis Warning" {
|
|
t.Fatalf("unexpected event type: %q", ev.EventType)
|
|
}
|
|
if ev.RawData == "" {
|
|
t.Fatalf("expected warning details in RawData")
|
|
}
|
|
}
|
|
|
|
func TestInferCollectedAtFromExtractedFiles_PrefersReliableMTime(t *testing.T) {
|
|
files := []ExtractedFile{
|
|
{Path: "a.log", ModTime: time.Date(1980, 1, 1, 0, 0, 0, 0, time.UTC)},
|
|
{Path: "b.log", ModTime: time.Date(2025, 12, 12, 10, 14, 49, 0, time.FixedZone("EST", -5*3600))},
|
|
{Path: "c.log", ModTime: time.Date(2026, 2, 28, 4, 18, 18, 0, time.FixedZone("UTC+8", 8*3600))},
|
|
}
|
|
|
|
got := InferCollectedAtFromExtractedFiles(files)
|
|
want := files[2].ModTime
|
|
if !got.Equal(want) {
|
|
t.Fatalf("expected %s, got %s", want, got)
|
|
}
|
|
}
|
|
|
|
func TestInferCollectedAtFromExtractedFiles_FallsBackToAnyMTime(t *testing.T) {
|
|
files := []ExtractedFile{
|
|
{Path: "a.log", ModTime: time.Date(1980, 1, 1, 0, 0, 0, 0, time.UTC)},
|
|
{Path: "b.log", ModTime: time.Date(1970, 1, 2, 0, 0, 0, 0, time.UTC)},
|
|
}
|
|
|
|
got := InferCollectedAtFromExtractedFiles(files)
|
|
want := files[0].ModTime
|
|
if !got.Equal(want) {
|
|
t.Fatalf("expected fallback %s, got %s", want, got)
|
|
}
|
|
}
|
|
|
|
func TestParseYearlessInDefaultArchiveLocation(t *testing.T) {
|
|
ref := time.Date(2026, 1, 3, 12, 0, 0, 0, time.UTC)
|
|
if got := ParseYearlessInDefaultArchiveLocation("Jan 2 15:04:05", "Dec 30 10:00:00", ref); got.Year() != 2025 {
|
|
t.Fatalf("expected rollover to previous year, got %s", got)
|
|
}
|
|
if got := ParseYearlessInDefaultArchiveLocation("Jan 2 15:04:05", "Jan 2 10:00:00", ref); got.Year() != 2026 {
|
|
t.Fatalf("expected collection year, got %s", got)
|
|
}
|
|
if got := ParseYearlessInDefaultArchiveLocation("Jan 2 15:04:05", "Jan 2 10:00:00", time.Time{}); !got.IsZero() {
|
|
t.Fatalf("unknown collection time must not invent a year, got %s", got)
|
|
}
|
|
}
|