1
0
mirror of https://github.com/golang/go synced 2024-09-29 14:24:32 -06:00

os/user: don't skip TestLookupGroup if supported

CL 37664 implemented this functionality, yet the tests were skipped.

Introduce and use additional variable groupListImplemented to
distinguish between these cases and enable TestLookupGroup for
supported configurations (which looks like all but plan9).

Change-Id: Iabaa7f08b4551dc67e67bdb6e715f15bb20d6218
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Reviewed-on: https://go-review.googlesource.com/c/go/+/330751
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
This commit is contained in:
Kir Kolyshkin 2021-06-22 20:26:31 -07:00 committed by Ian Lance Taylor
parent de1c934b97
commit 41b99dab0f
5 changed files with 20 additions and 7 deletions

View File

@ -20,6 +20,7 @@ const (
func init() { func init() {
userImplemented = false userImplemented = false
groupImplemented = false groupImplemented = false
groupListImplemented = false
} }
func current() (*User, error) { func current() (*User, error) {

View File

@ -16,7 +16,7 @@ import (
) )
func init() { func init() {
groupImplemented = false groupListImplemented = false
} }
func current() (*User, error) { func current() (*User, error) {

View File

@ -18,13 +18,15 @@ import (
"strings" "strings"
) )
const groupFile = "/etc/group" const (
const userFile = "/etc/passwd" groupFile = "/etc/group"
userFile = "/etc/passwd"
)
var colon = []byte{':'} var colon = []byte{':'}
func init() { func init() {
groupImplemented = false groupListImplemented = false
} }
// lineFunc returns a value, an error, or (nil, nil) to skip the row. // lineFunc returns a value, an error, or (nil, nil) to skip the row.

View File

@ -20,9 +20,12 @@ import (
"strconv" "strconv"
) )
// These may be set to false in init() for a particular platform and/or
// build flags to let the tests know to skip tests of some features.
var ( var (
userImplemented = true // set to false by lookup_stubs.go's init userImplemented = true
groupImplemented = true // set to false by lookup_stubs.go's init groupImplemented = true
groupListImplemented = true
) )
// User represents a user account. // User represents a user account.

View File

@ -119,8 +119,15 @@ func TestLookupGroup(t *testing.T) {
} }
} }
func checkGroupList(t *testing.T) {
t.Helper()
if !groupListImplemented {
t.Skip("user: group list not implemented; skipping test")
}
}
func TestGroupIds(t *testing.T) { func TestGroupIds(t *testing.T) {
checkGroup(t) checkGroupList(t)
if runtime.GOOS == "aix" { if runtime.GOOS == "aix" {
t.Skip("skipping GroupIds, see golang.org/issue/30563") t.Skip("skipping GroupIds, see golang.org/issue/30563")
} }