resources: Do not return GID for UID lookup

On linux it is convention for users to have a group with the same GID as the users UID. On macOS this is not the case. This broke the test which lead to discovering this bug.
This commit is contained in:
Johan Bloemberg
2018-02-09 17:17:55 +01:00
committed by James Shubin
parent d567dc3769
commit 8fb0373f82
2 changed files with 7 additions and 2 deletions

View File

@@ -248,7 +248,7 @@ func GetUID(username string) (int, error) {
userObj, err = user.Lookup(username)
if err == nil {
return strconv.Atoi(userObj.Gid)
return strconv.Atoi(userObj.Uid)
}
return -1, errwrap.Wrapf(err, "user lookup error (%s)", username)

View File

@@ -334,7 +334,12 @@ func TestCurrentUserGroupByName(t *testing.T) {
t.Errorf("uid didn't match current user's: %s vs %s", strconv.Itoa(uid), currentUID)
}
if gid, err = GetGID(userObj.Username); err != nil {
// macOS users do not have a group with their name on it, so not assuming this here
group, err := user.LookupGroupId(currentGID)
if err != nil {
t.Errorf("failed to lookup group by id: %s", currentGID)
}
if gid, err = GetGID(group.Name); err != nil {
t.Errorf("error trying to lookup current user UID: %s", err.Error())
}