summaryrefslogtreecommitdiff
path: root/internal/tui/dashboard/syscalls_test.go
blob: dfb6384763302cb02f78057020a8a6a3912473a3 (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
package dashboard

import (
	"strings"
	"testing"

	"ior/internal/statsengine"
)

func TestRenderSyscallsIncludesHeaders(t *testing.T) {
	snap := statsengine.NewSnapshot(
		nil, nil, nil,
		[]statsengine.SyscallSnapshot{
			{Name: "write", Count: 5, RatePerSec: 1.2, Bytes: 1024, Errors: 1},
			{Name: "read", Count: 10, RatePerSec: 2.4, Bytes: 2048, Errors: 0},
		},
		nil, nil,
		statsengine.HistogramSnapshot{},
		statsengine.HistogramSnapshot{},
	)

	out := renderSyscalls(&snap, 120, 30)
	for _, token := range []string{"Syscall", "Count", "Rate/s", "p95", "p99", "Bytes", "Errors"} {
		if !strings.Contains(out, token) {
			t.Fatalf("expected token %q in syscall table view", token)
		}
	}
	if !strings.Contains(out, "read") {
		t.Fatalf("expected syscall row in output")
	}
}

func TestFormatDurationNs(t *testing.T) {
	if got := formatDurationNs(50); got != "50ns" {
		t.Fatalf("unexpected ns formatting: %q", got)
	}
	if got := formatDurationNs(1500); !strings.Contains(got, "µs") {
		t.Fatalf("expected µs formatting, got %q", got)
	}
	if got := formatDurationNs(2_500_000); !strings.Contains(got, "ms") {
		t.Fatalf("expected ms formatting, got %q", got)
	}
}

func TestClampOffset(t *testing.T) {
	if got := clampOffset(-5, 10); got != 0 {
		t.Fatalf("expected 0 for negative offset, got %d", got)
	}
	if got := clampOffset(99, 4); got != 3 {
		t.Fatalf("expected max index clamp, got %d", got)
	}
}