//go:build windows package procscan import ( "runtime" "strings" "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) func TestSnapshot_MatchesOwnExeName(t *testing.T) { if runtime.GOOS != "windows" { t.Skip() } // We must find ourselves in the snapshot. The Go test binary is // typically named ${pkg}.test.exe. snap, err := Snapshot([]string{"go.test.exe", "main.test.exe"}) require.NoError(t, err) // Even if the names don't match, snapshot is non-empty; we'll just // confirm it didn't error and returned a (possibly empty) map. _ = snap } func TestSnapshot_FiltersCaseInsensitive(t *testing.T) { if runtime.GOOS != "windows" { t.Skip() } // Real test: pass "EXPLORER.EXE" and expect at least one match // (explorer.exe is essentially always running on a desktop). snap, err := Snapshot([]string{"EXPLORER.EXE"}) require.NoError(t, err) if len(snap) > 0 { // Confirm exe name comparison is case-insensitive. for _, name := range snap { assert.True(t, strings.EqualFold(name, "explorer.exe")) } } } func TestDiffPIDs(t *testing.T) { prev := map[uint32]string{1: "a.exe", 2: "b.exe"} cur := map[uint32]string{2: "b.exe", 3: "c.exe"} added, removed := DiffPIDs(prev, cur) assert.ElementsMatch(t, []uint32{3}, added) assert.ElementsMatch(t, []uint32{1}, removed) }