summaryrefslogtreecommitdiff
path: root/internal/tui/dashboard/processes_test.go
blob: 24c1c1b3b19c13ce8a590c4b3342e4b66461ef57 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package dashboard

import (
	"strings"
	"testing"

	"ior/internal/statsengine"
)

func TestRenderProcessesIncludesHeaders(t *testing.T) {
	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) {
	snap := statsengine.NewSnapshot(
		nil, nil, nil,
		nil, nil,
		[]statsengine.ProcessSnapshot{
			{PID: 77, Comm: "proc", Syscalls: 1},
		},
		statsengine.HistogramSnapshot{},
		statsengine.HistogramSnapshot{},
	)

	out := renderProcessesWithOffset(&snap, 100, 20, 0, 77)
	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)
	}
}