Files
bjarneo--cliamp/ipc/process_windows_test.go
GVASTE d6c50ed623 windows: fix config, IPC, path, and Lua compatibility (#258)
* windows: fix config, IPC, path, and Lua compatibility

* spotify: share API structures and helper so tests compile on Windows

* windows: address PR comments and fix socket unavailable detection, tasklist matching, api_fs tests, and doc comment

* windows: address remaining PR reviews (table-driven tests, m3u resolve comments & tests, blockquote formatting, and site/index.html description)

* feat: implement cross-platform IPC server with Unix and Windows support

* feat: implement Unix socket IPC server and Windows process liveness check

* ipc: detect dead processes via os.ErrProcessDone

os.Process.Signal converts ESRCH to os.ErrProcessDone since Go 1.16, so
comparing against raw syscall.ESRCH never matched and a stale socket from
a crashed instance made NewServer fail instead of cleaning it up.

* windows: simplify fs allowlist normalization, exec env, and ipc error checks

- normalize write allow-dirs once in the memoized writeAllowDirs
- collapse duplicate test helpers and repeated getenv blocks
- drop redundant errors.As branch; name WSAECONNREFUSED
- revert single-entry table test to linear form
- gofmt: trailing newlines and indentation

---------

Co-authored-by: Bjarne Øverli <bjarne.oeverli@gmail.com>
2026-06-04 19:52:32 +02:00

35 lines
683 B
Go

//go:build windows
package ipc
import (
"math"
"os"
"testing"
)
func TestProcessAlive(t *testing.T) {
tests := []struct {
name string
pid int
want bool
}{
{name: "negative pid", pid: -1, want: false},
{name: "zero pid", pid: 0, want: false},
{name: "current process", pid: os.Getpid(), want: true},
{name: "unlikely pid", pid: math.MaxInt32, want: false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := processAlive(tt.pid)
if err != nil {
t.Fatalf("processAlive(%d) unexpected error: %v", tt.pid, err)
}
if got != tt.want {
t.Fatalf("processAlive(%d) = %v, want %v", tt.pid, got, tt.want)
}
})
}
}