package inspur import ( "testing" "time" "git.mchus.pro/mchus/logpile/internal/models" ) func TestDedupSELEvents(t *testing.T) { ts := time.Date(2026, 7, 27, 4, 52, 55, 0, time.UTC) events := []models.Event{ {Source: "SEL", Timestamp: ts, EventType: "Asserted", Description: "PSU0 fail"}, {Source: "SEL", Timestamp: ts, EventType: "Asserted", Description: "PSU0 fail"}, {Source: "BMC", Timestamp: ts, EventType: "Assert", Description: "recurring alarm"}, {Source: "BMC", Timestamp: ts, EventType: "Assert", Description: "recurring alarm"}, } out := dedupSELEvents(events) if len(out) != 3 { t.Fatalf("expected 3 events (1 SEL dup removed, BMC untouched), got %d: %+v", len(out), out) } } func TestParseSELListWithLocation_UsesProvidedTimezone(t *testing.T) { content := []byte("sel elist:\n1,02/28/2026,04:18:18,Sensor X,Event,Asserted\n") shanghai, err := time.LoadLocation("Asia/Shanghai") if err != nil { t.Fatalf("load location: %v", err) } events := ParseSELListWithLocation(content, shanghai) if len(events) != 1 { t.Fatalf("expected 1 event, got %d", len(events)) } // 04:18:18 +08:00 == 20:18:18Z (previous day) want := time.Date(2026, 2, 27, 20, 18, 18, 0, time.UTC) if !events[0].Timestamp.UTC().Equal(want) { t.Fatalf("unexpected timestamp: got %s want %s", events[0].Timestamp.UTC(), want) } } func TestParseTimezoneConfigLocation(t *testing.T) { content := []byte("[TimeZoneConfig]\ntimezone=Asia/Shanghai\n") got := parseTimezoneConfigLocation(content) if got != "Asia/Shanghai" { t.Fatalf("unexpected timezone: %q", got) } }