Files
logpile/internal/exporter/reanimator_event_logs_test.go
Mikhail ChusavitinandClaude Opus 5.5 cb2e38223e chore: update parser module to v38.0.0, script parser bumps
Move logpile to git.mchus.pro/reanimator/parser/v38 v38.0.0 (ADL-085).
Add scripts/bump-parser.sh, which bumps the parser, tests, commits, tags
the release as v<counter>.<parser major>, pushes and builds (ADL-086).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 18:07:28 +03:00

62 lines
2.8 KiB
Go

package exporter
import (
"testing"
"time"
"git.mchus.pro/reanimator/parser/v38/models"
)
func TestConvertEventLogs_UndatedEventHasNoEventTime(t *testing.T) {
logs := convertEventLogs([]models.Event{{Source: "BMC", Description: "FAN3 reports Critical"}})
if len(logs) != 1 {
t.Fatalf("expected 1 log, got %d", len(logs))
}
if logs[0].EventTime != "" {
t.Fatalf("event without source time must not get collection time, got %q", logs[0].EventTime)
}
}
func TestConvertEventLogs_IsActive(t *testing.T) {
t0 := time.Date(2026, 8, 12, 10, 0, 0, 0, time.UTC)
yes := true
events := []models.Event{
// 0..2: condition with lifecycle, latest Assert still open.
{Timestamp: t0, Source: "BMC", SensorType: "memory", SensorName: "CPU0_C2D1", ID: "0C090401", EventType: "Assert", Description: "disabled"},
{Timestamp: t0.Add(time.Minute), Source: "BMC", SensorType: "memory", SensorName: "CPU0_C2D1", ID: "0C090401", EventType: "Deassert", Description: "disabled"},
{Timestamp: t0.Add(2 * time.Minute), Source: "BMC", SensorType: "memory", SensorName: "CPU0_C2D1", ID: "0C090401", EventType: "Assert", Description: "disabled"},
// 3: one-shot Assert without lifecycle.
{Timestamp: t0, Source: "BMC", SensorType: "sys restart", SensorName: "SYS RESTART", ID: "1D020000", EventType: "Assert", Description: "restart"},
// 4: explicit snapshot state.
{Source: "BMC", SensorType: "fan", SensorName: "FAN3", EventType: "Fan Status", Description: "FAN3 reports Critical", Active: &yes},
// 5: SEL-style record: condition in EventType, phase in RawData.
{Timestamp: t0, Source: "SEL", SensorType: "power supply", SensorName: "PSU0_Status", ID: "10", EventType: "Predictive failure", RawData: "Asserted", Description: "Predictive failure"},
{Timestamp: t0.Add(time.Minute), Source: "SEL", SensorType: "power supply", SensorName: "PSU0_Status", ID: "15", EventType: "Predictive failure", RawData: "Deasserted", Description: "Predictive failure"},
}
logs := convertEventLogs(events)
want := []*bool{ptrBool(false), ptrBool(false), nil, nil, ptrBool(true), ptrBool(false), ptrBool(false)}
for i, w := range want {
got := logs[i].IsActive
switch {
case w == nil && got != nil:
t.Fatalf("log %d: expected is_active unset, got %v", i, *got)
case w != nil && (got == nil || *got != *w):
t.Fatalf("log %d: expected is_active=%v, got %v", i, *w, got)
}
}
}
func ptrBool(v bool) *bool { return &v }
func TestConvertEventLogs_EasyBeeSources(t *testing.T) {
logs := convertEventLogs([]models.Event{
{Source: "ipmi-sel", Description: "Transition to Non-critical from OK"},
{Source: "dmesg", Description: "usb 1-1: device not accepting address 3, error -71"},
{Source: "Bee Runtime", Description: "Bee runtime status: PARTIAL"},
})
if len(logs) != 2 || logs[0].Source != "bmc" || logs[1].Source != "host" {
t.Fatalf("unexpected event_logs: %+v", logs)
}
}