summaryrefslogtreecommitdiff
path: root/user_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'user_test.go')
-rw-r--r--user_test.go81
1 files changed, 81 insertions, 0 deletions
diff --git a/user_test.go b/user_test.go
new file mode 100644
index 00000000..3a9f6da9
--- /dev/null
+++ b/user_test.go
@@ -0,0 +1,81 @@
+package roadrunner
+
+import (
+ "testing"
+ "runtime"
+ "github.com/stretchr/testify/assert"
+ "os/user"
+)
+
+func Test_ResolveUser_Error(t *testing.T) {
+ if runtime.GOOS == "windows" {
+ t.Skip("not supported on " + runtime.GOOS)
+ }
+
+ u, err := resolveUser("-1")
+ assert.Nil(t, u)
+ assert.Error(t, err)
+
+ u, err = resolveUser("random-user")
+ assert.Nil(t, u)
+ assert.Error(t, err)
+}
+
+func Test_ResolveUser(t *testing.T) {
+ if runtime.GOOS == "windows" {
+ t.Skip("not supported on " + runtime.GOOS)
+ }
+
+ current, err := user.Current()
+ assert.NotNil(t, current)
+ assert.NoError(t, err)
+
+ u, err := resolveUser(current.Uid)
+ assert.NoError(t, err)
+ assert.NotNil(t, u)
+ assert.Equal(t, current.Uid, u.Uid)
+
+ u, err = resolveUser(current.Name)
+ assert.NoError(t, err)
+ assert.NotNil(t, u)
+ assert.Equal(t, current.Uid, u.Uid)
+
+ u, err = resolveUser(current.Username)
+ assert.NoError(t, err)
+ assert.NotNil(t, u)
+ assert.Equal(t, current.Uid, u.Uid)
+}
+
+func Test_ResolveGroup_Error(t *testing.T) {
+ if runtime.GOOS == "windows" {
+ t.Skip("not supported on " + runtime.GOOS)
+ }
+
+ g, err := resolveGroup("-1")
+ assert.Nil(t, g)
+ assert.Error(t, err)
+
+ g, err = resolveGroup("random-group")
+ assert.Nil(t, g)
+ assert.Error(t, err)
+}
+
+func Test_ResolveGroup(t *testing.T) {
+ if runtime.GOOS == "windows" {
+ t.Skip("not supported on " + runtime.GOOS)
+ }
+
+ current, err := user.Current()
+ assert.NotNil(t, current)
+ assert.NoError(t, err)
+
+ g, err := resolveGroup(current.Gid)
+ assert.NoError(t, err)
+ assert.NotNil(t, g)
+ assert.Equal(t, current.Gid, g.Gid)
+
+ g2, err := resolveGroup(g.Name)
+ assert.NoError(t, err)
+ assert.NotNil(t, g2)
+ assert.Equal(t, g2.Gid, g.Gid)
+}