diff --git a/resources/util.go b/resources/util.go index 07b4ae45..286aebf3 100644 --- a/resources/util.go +++ b/resources/util.go @@ -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) diff --git a/resources/util_test.go b/resources/util_test.go index 936f26b6..aefdd913 100644 --- a/resources/util_test.go +++ b/resources/util_test.go @@ -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()) }