d6c50ed623
* 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>
67 lines
1.3 KiB
Go
67 lines
1.3 KiB
Go
package ipc
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"syscall"
|
|
"testing"
|
|
)
|
|
|
|
func TestIsSocketUnavailable(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
err error
|
|
want bool
|
|
}{
|
|
{
|
|
name: "windows dead network AF_UNIX error",
|
|
err: errors.New("connect: A socket operation encountered a dead network"),
|
|
want: true,
|
|
},
|
|
{
|
|
name: "actively refused",
|
|
err: errors.New("connect: No connection could be made because the target machine actively refused it"),
|
|
want: true,
|
|
},
|
|
{
|
|
name: "unrelated network error",
|
|
err: errors.New("connect: some other error"),
|
|
want: false,
|
|
},
|
|
{
|
|
name: "nil error",
|
|
err: nil,
|
|
want: false,
|
|
},
|
|
{
|
|
name: "wrapped not-exist",
|
|
err: fmt.Errorf("dial: %w", os.ErrNotExist),
|
|
want: true,
|
|
},
|
|
{
|
|
name: "wrapped ECONNREFUSED",
|
|
err: fmt.Errorf("dial: %w", syscall.ECONNREFUSED),
|
|
want: true,
|
|
},
|
|
{
|
|
name: "WSAECONNREFUSED error",
|
|
err: syscall.Errno(10061),
|
|
want: true,
|
|
},
|
|
{
|
|
name: "wrapped WSAECONNREFUSED error",
|
|
err: fmt.Errorf("dial: %w", syscall.Errno(10061)),
|
|
want: true,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got := isSocketUnavailable(tt.err); got != tt.want {
|
|
t.Fatalf("isSocketUnavailable(%v) = %v, want %v", tt.err, got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|