Update test to check for full FreeBSD support

This commit is contained in:
2025-04-04 00:37:25 -04:00
parent b822d55619
commit 5b200e3321
2 changed files with 10 additions and 16 deletions
+2 -2
View File
@@ -16,8 +16,8 @@ type Creds struct {
uid string uid string
} }
func (c *Creds) PID() (pid int, ok bool) { func (c *Creds) PID() (pid int) {
return c.pid, c.pid != 0 return c.pid
} }
// UserID returns the userid (or Windows SID) that owns the other side // UserID returns the userid (or Windows SID) that owns the other side
+8 -14
View File
@@ -11,7 +11,6 @@ import (
"net" "net"
"os" "os"
"path/filepath" "path/filepath"
"runtime"
"testing" "testing"
) )
@@ -52,23 +51,18 @@ func TestUnixSock(t *testing.T) {
} }
uid := creds.UserID() uid := creds.UserID()
if !ok { if uid == "" {
t.Errorf("no UID") t.Errorf("no UID")
} }
if got, want := uid, fmt.Sprint(os.Getuid()); got != want { if got, want := uid, fmt.Sprint(os.Getuid()); got != want {
t.Errorf("UID = %q; want %q", got, want) t.Errorf("UID = %q; want %q", got, want)
} }
pid, ok := creds.PID()
if runtime.GOOS == "freebsd" { pid := creds.PID()
if ok { if pid == 0 {
t.Error("PID ok; want !ok. Thank you for fixing FreeBSD, please update the test.") t.Errorf("no PID")
} }
} else { if got, want := pid, os.Getpid(); got != want {
if !ok { t.Errorf("PID = %v; want %v", got, want)
t.Errorf("no PID")
}
if got, want := pid, os.Getpid(); got != want {
t.Errorf("PID = %v; want %v", got, want)
}
} }
} }