diff options
| author | Paul Buetow <paul@buetow.org> | 2026-02-24 08:49:57 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-02-24 08:49:57 +0200 |
| commit | 13a81c7fdbaab8ef650a7487270abb6776f0b4cd (patch) | |
| tree | 111a76dfb4516a62ed166b2a4486214f1034929d /internal/tui/dashboard/processes_test.go | |
| parent | e5116514c33b2fce6ce2fc7904d6720c5236221f (diff) | |
tui: add dashboard processes table tab
Diffstat (limited to 'internal/tui/dashboard/processes_test.go')
| -rw-r--r-- | internal/tui/dashboard/processes_test.go | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/internal/tui/dashboard/processes_test.go b/internal/tui/dashboard/processes_test.go new file mode 100644 index 0000000..4db490d --- /dev/null +++ b/internal/tui/dashboard/processes_test.go @@ -0,0 +1,61 @@ +package dashboard + +import ( + "strings" + "testing" + + "ior/internal/flags" + "ior/internal/statsengine" +) + +func TestRenderProcessesIncludesHeaders(t *testing.T) { + flags.SetPidFilter(-1) + + snap := statsengine.NewSnapshot( + nil, nil, nil, + nil, nil, + []statsengine.ProcessSnapshot{ + {PID: 200, Comm: "proc-b", Syscalls: 10, RatePerSec: 2.3, Bytes: 2048, AvgLatencyNs: 1500}, + {PID: 100, Comm: "proc-a", Syscalls: 20, RatePerSec: 4.6, Bytes: 4096, AvgLatencyNs: 2500}, + }, + statsengine.HistogramSnapshot{}, + statsengine.HistogramSnapshot{}, + ) + + out := renderProcesses(&snap, 120, 30) + for _, token := range []string{"PID", "Comm", "Syscalls", "Total Bytes", "Avg Latency"} { + if !strings.Contains(out, token) { + t.Fatalf("expected header token %q", token) + } + } + if !strings.Contains(out, "100") || !strings.Contains(out, "proc-a") { + t.Fatalf("expected process row in output") + } +} + +func TestRenderProcessesShowsSinglePIDNote(t *testing.T) { + flags.SetPidFilter(77) + t.Cleanup(func() { flags.SetPidFilter(-1) }) + + snap := statsengine.NewSnapshot( + nil, nil, nil, + nil, nil, + []statsengine.ProcessSnapshot{ + {PID: 77, Comm: "proc", Syscalls: 1}, + }, + statsengine.HistogramSnapshot{}, + statsengine.HistogramSnapshot{}, + ) + + out := renderProcesses(&snap, 100, 20) + if !strings.Contains(out, "most useful with All PIDs") { + t.Fatalf("expected single-pid guidance note") + } +} + +func TestTruncateText(t *testing.T) { + got := truncateText("very-long-process-name", 10) + if got != "very-lo..." { + t.Fatalf("unexpected truncation result: %q", got) + } +} |
