Fix unit test to run with random UID

User that runs the tests desn't need to be in /etc/passwd and thus
user.Current() can fail. Assume the user is not root in this case.
This commit is contained in:
Jan Safranek 2018-11-19 13:08:54 +01:00
parent 7ba79c3183
commit cfbf6aa925

View File

@ -169,11 +169,19 @@ func newFakeNsenterMounter(tmpdir string, t *testing.T) (mounter *NsenterMounter
}
func TestNsenterExistsFile(t *testing.T) {
user, err := user.Current()
if err != nil {
t.Error(err)
var isRoot bool
usr, err := user.Current()
if err == nil {
isRoot = usr.Username == "root"
} else {
switch err.(type) {
case user.UnknownUserIdError:
// Root should be always known, this is some random UID
isRoot = false
default:
t.Fatal(err)
}
}
isRoot := user.Username == "root"
tests := []struct {
name string