This giant patch makes some much needed improvements to the code base. * The engine has been rewritten and lives within engine/graph/ * All of the common interfaces and code now live in engine/ * All of the resources are in one package called engine/resources/ * The Res API can use different "traits" from engine/traits/ * The Res API has been simplified to hide many of the old internals * The Watch & Process loops were previously inverted, but is now fixed * The likelihood of package cycles has been reduced drastically * And much, much more... Unfortunately, some code had to be temporarily removed. The remote code had to be taken out, as did the prometheus code. We hope to have these back in new forms as soon as possible.
106 lines
3.0 KiB
Go
106 lines
3.0 KiB
Go
// Mgmt
|
|
// Copyright (C) 2013-2018+ James Shubin and the project contributors
|
|
// Written by James Shubin <james@shubin.ca> and the project contributors
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
package util
|
|
|
|
import (
|
|
"os/user"
|
|
"strconv"
|
|
"testing"
|
|
)
|
|
|
|
func TestUnknownGroup(t *testing.T) {
|
|
gid, err := GetGID("unknowngroup")
|
|
if err == nil {
|
|
t.Errorf("expected failure, but passed with: %d", gid)
|
|
}
|
|
}
|
|
|
|
func TestUnknownUser(t *testing.T) {
|
|
uid, err := GetUID("unknownuser")
|
|
if err == nil {
|
|
t.Errorf("expected failure, but passed with: %d", uid)
|
|
}
|
|
}
|
|
|
|
func TestCurrentUserGroupByName(t *testing.T) {
|
|
// get current user
|
|
userObj, err := user.Current()
|
|
if err != nil {
|
|
t.Errorf("error trying to lookup current user: %s", err.Error())
|
|
}
|
|
|
|
currentUID := userObj.Uid
|
|
currentGID := userObj.Gid
|
|
|
|
var uid int
|
|
var gid int
|
|
|
|
// now try to get the uid/gid via our API (via username and group name)
|
|
if uid, err = GetUID(userObj.Username); err != nil {
|
|
t.Errorf("error trying to lookup current user UID: %s", err.Error())
|
|
}
|
|
|
|
if strconv.Itoa(uid) != currentUID {
|
|
t.Errorf("uid didn't match current user's: %s vs %s", strconv.Itoa(uid), currentUID)
|
|
}
|
|
|
|
// 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())
|
|
}
|
|
|
|
if strconv.Itoa(gid) != currentGID {
|
|
t.Errorf("gid didn't match current user's: %s vs %s", strconv.Itoa(gid), currentGID)
|
|
}
|
|
}
|
|
|
|
func TestCurrentUserGroupById(t *testing.T) {
|
|
// get current user
|
|
userObj, err := user.Current()
|
|
if err != nil {
|
|
t.Errorf("error trying to lookup current user: %s", err.Error())
|
|
}
|
|
|
|
currentUID := userObj.Uid
|
|
currentGID := userObj.Gid
|
|
|
|
var uid int
|
|
var gid int
|
|
|
|
// now try to get the uid/gid via our API (via uid and gid)
|
|
if uid, err = GetUID(currentUID); err != nil {
|
|
t.Errorf("error trying to lookup current user UID: %s", err.Error())
|
|
}
|
|
|
|
if strconv.Itoa(uid) != currentUID {
|
|
t.Errorf("uid didn't match current user's: %s vs %s", strconv.Itoa(uid), currentUID)
|
|
}
|
|
|
|
if gid, err = GetGID(currentGID); err != nil {
|
|
t.Errorf("error trying to lookup current user UID: %s", err.Error())
|
|
}
|
|
|
|
if strconv.Itoa(gid) != currentGID {
|
|
t.Errorf("gid didn't match current user's: %s vs %s", strconv.Itoa(gid), currentGID)
|
|
}
|
|
}
|