forked from gookit/goutil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_test.go
51 lines (39 loc) · 1.05 KB
/
user_test.go
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
package sysutil_test
import (
"testing"
"github.com/gookit/goutil/dump"
"github.com/gookit/goutil/sysutil"
"github.com/gookit/goutil/testutil/assert"
)
func TestUserDir(t *testing.T) {
dir := sysutil.UserHomeDir()
assert.NotEmpty(t, dir)
dump.P(dir)
dir1 := sysutil.HomeDir()
assert.NotEmpty(t, dir1)
dir2 := sysutil.UHomeDir()
assert.NotEmpty(t, dir2)
assert.Eq(t, dir1, dir2)
dir = sysutil.UserDir("sub-path")
assert.Contains(t, dir, "/sub-path")
dump.P(dir)
dir = sysutil.UserCacheDir("my-logs")
assert.Contains(t, dir, ".cache/my-logs")
dump.P(dir)
dir = sysutil.UserConfigDir("my-conf")
assert.Contains(t, dir, ".config/my-conf")
dump.P(dir)
rawPath := "~/.kite"
assert.LenGt(t, sysutil.ExpandPath(rawPath), len(rawPath))
assert.Neq(t, rawPath, sysutil.ExpandHome(rawPath))
}
func TestWorkdir(t *testing.T) {
assert.NotEmpty(t, sysutil.Workdir())
}
func TestLoginUser(t *testing.T) {
cu := sysutil.LoginUser()
assert.NotEmpty(t, cu)
fu := sysutil.MustFindUser(cu.Username)
assert.NotEmpty(t, fu)
assert.Eq(t, cu.Uid, fu.Uid)
}