unix: check gid in TestGetsockoptXucred

macOS (and the BSDs) report all groups in Xucred, the first one being
the GID.

Also use Socketpair/Close from golang.org/x/sys/unix instead of package
syscall.

Change-Id: I9319ff2b5258f66afc24e3e80c704d816e995dbf
Reviewed-on: https://go-review.googlesource.com/c/sys/+/293569
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
diff --git a/unix/syscall_darwin_test.go b/unix/syscall_darwin_test.go
index aeefd53..eaebf2d 100644
--- a/unix/syscall_darwin_test.go
+++ b/unix/syscall_darwin_test.go
@@ -10,7 +10,6 @@
 	"net"
 	"os"
 	"path"
-	"syscall"
 	"testing"
 
 	"golang.org/x/sys/unix"
@@ -221,12 +220,12 @@
 }
 
 func TestGetsockoptXucred(t *testing.T) {
-	fds, err := syscall.Socketpair(syscall.AF_LOCAL, syscall.SOCK_STREAM, 0)
+	fds, err := unix.Socketpair(unix.AF_LOCAL, unix.SOCK_STREAM, 0)
 	if err != nil {
 		t.Fatalf("Socketpair: %v", err)
 	}
-	defer syscall.Close(fds[0])
-	defer syscall.Close(fds[1])
+	defer unix.Close(fds[0])
+	defer unix.Close(fds[1])
 
 	srvFile := os.NewFile(uintptr(fds[0]), "server")
 	defer srvFile.Close()
@@ -252,4 +251,9 @@
 	if got, want := cred.Uid, os.Getuid(); int(got) != int(want) {
 		t.Errorf("uid = %v; want %v", got, want)
 	}
+	if cred.Ngroups > 0 {
+		if got, want := cred.Groups[0], os.Getgid(); int(got) != int(want) {
+			t.Errorf("gid = %v; want %v", got, want)
+		}
+	}
 }