Commit cfbf6aa9 authored by Jan Safranek's avatar Jan Safranek

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.
parent 7ba79c31
...@@ -169,11 +169,19 @@ func newFakeNsenterMounter(tmpdir string, t *testing.T) (mounter *NsenterMounter ...@@ -169,11 +169,19 @@ func newFakeNsenterMounter(tmpdir string, t *testing.T) (mounter *NsenterMounter
} }
func TestNsenterExistsFile(t *testing.T) { func TestNsenterExistsFile(t *testing.T) {
user, err := user.Current() var isRoot bool
if err != nil { usr, err := user.Current()
t.Error(err) 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 { tests := []struct {
name string name string
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment