summaryrefslogtreecommitdiff
path: root/user_test.go
blob: 3a9f6da92fe352ac6ca3aaea1fc3abe9a154b540 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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)
}