Files
logpile/internal/server/chart_view_test.go
T
Mikhail ChusavitinandClaude Opus 5.5 ab53914d0a fix(chart): hide component status_history in chart view
Flapping components (e.g. DIMM CPU0_C2D1 with 13 transitions) stretched
table rows across several screens. The same journal events are already in
Event Logs, matched by component_ref. The Reanimator export keeps the field.

ADL-073.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-28 13:18:58 +03:00

122 lines
3.3 KiB
Go

package server
import (
"net/http"
"net/http/httptest"
"strings"
"testing"
"time"
"git.mchus.pro/mchus/logpile/internal/models"
)
func TestHandleChartCurrent_RendersCurrentReanimatorSnapshot(t *testing.T) {
s := New(Config{})
s.SetResult(&models.AnalysisResult{
SourceType: models.SourceTypeArchive,
Filename: "example.zip",
CollectedAt: time.Date(2026, 3, 16, 10, 0, 0, 0, time.UTC),
Hardware: &models.HardwareConfig{
BoardInfo: models.BoardInfo{
ProductName: "SYS-TEST",
SerialNumber: "SN123",
},
CPUs: []models.CPU{
{
Socket: 1,
Model: "Xeon Gold",
Cores: 32,
},
},
},
})
req := httptest.NewRequest(http.MethodGet, "/chart/current", nil)
rec := httptest.NewRecorder()
s.mux.ServeHTTP(rec, req)
if rec.Code != http.StatusOK {
t.Fatalf("expected 200, got %d", rec.Code)
}
body := rec.Body.String()
if !strings.Contains(body, "SYS-TEST - SN123") {
t.Fatalf("expected chart title in body, got %q", body)
}
if !strings.Contains(body, `static/view.css`) {
t.Fatalf("expected chart css path, got %q", body)
}
if !strings.Contains(body, `static/view.js`) {
t.Fatalf("expected chart js path, got %q", body)
}
if !strings.Contains(body, "Snapshot Metadata") {
t.Fatalf("expected rendered chart output, got %q", body)
}
}
func TestHandleChartCurrent_RendersEmptyViewerWithoutResult(t *testing.T) {
s := New(Config{})
req := httptest.NewRequest(http.MethodGet, "/chart/current", nil)
rec := httptest.NewRecorder()
s.mux.ServeHTTP(rec, req)
if rec.Code != http.StatusOK {
t.Fatalf("expected 200, got %d", rec.Code)
}
body := rec.Body.String()
if !strings.Contains(body, "Snapshot Viewer") {
t.Fatalf("expected empty chart viewer, got %q", body)
}
}
func TestHandleChartCurrent_HidesComponentStatusHistory(t *testing.T) {
changedAt := time.Date(2026, 8, 12, 7, 33, 0, 0, time.UTC)
s := New(Config{})
s.SetResult(&models.AnalysisResult{
SourceType: models.SourceTypeArchive,
Filename: "example.zip",
CollectedAt: time.Date(2026, 8, 12, 12, 0, 0, 0, time.UTC),
Hardware: &models.HardwareConfig{
BoardInfo: models.BoardInfo{ProductName: "SYS-TEST", SerialNumber: "SN123"},
Memory: []models.MemoryDIMM{
{
Slot: "CPU0_C2D1",
Present: true,
SizeMB: 65536,
SerialNumber: "SN-DIMM",
Status: "Warning",
StatusHistory: []models.StatusHistoryEntry{
{Status: "Warning", ChangedAt: changedAt, Details: "history-only details"},
},
},
},
},
})
exported, err := currentReanimatorSnapshotBytes(s.GetResult())
if err != nil {
t.Fatalf("currentReanimatorSnapshotBytes() error = %v", err)
}
if !strings.Contains(string(exported), "status_history") {
t.Fatalf("expected export snapshot to keep status_history")
}
req := httptest.NewRequest(http.MethodGet, "/chart/current", nil)
rec := httptest.NewRecorder()
s.mux.ServeHTTP(rec, req)
if rec.Code != http.StatusOK {
t.Fatalf("expected 200, got %d: %s", rec.Code, rec.Body.String())
}
body := rec.Body.String()
if !strings.Contains(body, "CPU0_C2D1") {
t.Fatalf("expected DIMM row in chart, got %q", body)
}
if strings.Contains(body, "status_history") || strings.Contains(body, "history-only details") {
t.Fatalf("expected status_history hidden from chart view")
}
}