summaryrefslogtreecommitdiff
path: root/internal/eventloop_seed_test.go
blob: 2b3574afcf53b89e1631aae1bd488d4d72b2b399 (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
package internal

import (
	"os"
	"testing"
)

func TestSeedTrackedPidCommCachesTrackedPidComm(t *testing.T) {
	pid := uint32(os.Getpid())
	el := &eventLoop{
		cfg: eventLoopConfig{
			pidFilter: int(pid),
		},
		comms: make(map[uint32]string),
	}

	want := el.comm(pid)
	if want == "" {
		t.Fatalf("expected comm for pid %d", pid)
	}
	delete(el.comms, pid)

	el.seedTrackedPidComm()

	if got := el.comms[pid]; got != want {
		t.Fatalf("seeded comm = %q, want %q", got, want)
	}
}

func TestSeedTrackedPidCommSkipsWhenPidFilterDisabled(t *testing.T) {
	el := &eventLoop{
		cfg: eventLoopConfig{
			pidFilter: -1,
		},
		comms: make(map[uint32]string),
	}

	el.seedTrackedPidComm()

	if len(el.comms) != 0 {
		t.Fatalf("expected no comms to be seeded when pid filter is disabled")
	}
}