summaryrefslogtreecommitdiff
path: root/internal/statsengine/snapshot_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-02-24 12:21:42 +0200
committerPaul Buetow <paul@buetow.org>2026-02-24 12:21:42 +0200
commitd93d286b6b214f12e65214360a41f8668123f174 (patch)
tree1113fbb7c7dbd08373d7db14bc791bb85eaafd80 /internal/statsengine/snapshot_test.go
parentbd3c53086a3fe3ac177f4c656d1e521a2f0595b1 (diff)
statsengine: add top-n snapshot helpers for overview
Diffstat (limited to 'internal/statsengine/snapshot_test.go')
-rw-r--r--internal/statsengine/snapshot_test.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/internal/statsengine/snapshot_test.go b/internal/statsengine/snapshot_test.go
index e5c3caa..277fa0d 100644
--- a/internal/statsengine/snapshot_test.go
+++ b/internal/statsengine/snapshot_test.go
@@ -103,3 +103,26 @@ func TestNilAccessorsRemainNil(t *testing.T) {
t.Fatalf("expected nil buckets, got %#v", got)
}
}
+
+func TestTopNAccessors(t *testing.T) {
+ s := NewSnapshot(
+ nil,
+ nil,
+ nil,
+ []SyscallSnapshot{{Name: "a"}, {Name: "b"}, {Name: "c"}},
+ []FileSnapshot{{Path: "/a"}, {Path: "/b"}},
+ []ProcessSnapshot{{PID: 1}, {PID: 2}, {PID: 3}},
+ HistogramSnapshot{},
+ HistogramSnapshot{},
+ )
+
+ if got := s.TopNSyscalls(2); len(got) != 2 {
+ t.Fatalf("expected 2 top syscalls, got %d", len(got))
+ }
+ if got := s.TopNFiles(10); len(got) != 2 {
+ t.Fatalf("expected all files when n exceeds len, got %d", len(got))
+ }
+ if got := s.TopNProcesses(0); got != nil {
+ t.Fatalf("expected nil when n<=0, got %#v", got)
+ }
+}