-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcg_test.go
41 lines (34 loc) · 1.1 KB
/
cg_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
package cgroup
import (
"os/user"
"testing"
)
func TestUidGid(t *testing.T) {
Init()
var wantTaskUid, wantCtrlUid UID
var wantTaskGid, wantCtrlGid GID
curUser, err := user.Current()
if err == nil {
wantTaskUid = stringToUID(curUser.Uid)
wantTaskGid = stringToGID(curUser.Gid)
wantCtrlUid = stringToUID(curUser.Uid)
wantCtrlGid = stringToGID(curUser.Gid)
} else {
t.Logf("cannot get the current user. fall back to 0.\n")
wantTaskUid, wantTaskGid, wantCtrlUid, wantCtrlGid = 0, 0, 0, 0
}
cg := NewCgroup("test_cgroup")
if err := cg.SetUIDGID(wantTaskUid, wantTaskGid, wantCtrlUid, wantCtrlGid); err != nil {
t.Fatalf("cannot set cgroup uids/gids: %v\n", err)
}
gotTaskUid, gotTaskGid, gotCtrlUid, gotCtrlGid, err := cg.GetUIDGID()
if err != nil {
t.Fatalf("cannot get cgroup uids/gids: %v\n", err)
}
if wantTaskUid != gotTaskUid || wantTaskGid != gotTaskGid ||
wantCtrlUid != gotCtrlUid || wantCtrlGid != gotCtrlGid {
t.Fatalf("wanted (%d,%d,%d,%d), got (%d,%d,%d,%d)\n",
wantTaskUid, wantTaskGid, wantCtrlUid, wantCtrlGid,
gotTaskUid, gotTaskGid, gotCtrlUid, gotCtrlGid)
}
}