forked from shirou/gopsutil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker_linux_test.go
83 lines (73 loc) · 1.53 KB
/
docker_linux_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
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
82
83
//go:build linux
// +build linux
package docker
import "testing"
func TestGetDockerIDList(t *testing.T) {
// If there is not docker environment, this test always fail.
// not tested here
/*
_, err := GetDockerIDList()
if err != nil {
t.Errorf("error %v", err)
}
*/
}
func TestGetDockerStat(t *testing.T) {
// If there is not docker environment, this test always fail.
// not tested here
/*
ret, err := GetDockerStat()
if err != nil {
t.Errorf("error %v", err)
}
if len(ret) == 0 {
t.Errorf("ret is empty")
}
empty := CgroupDockerStat{}
for _, v := range ret {
if empty == v {
t.Errorf("empty CgroupDockerStat")
}
if v.ContainerID == "" {
t.Errorf("Could not get container id")
}
}
*/
}
func TestCgroupCPU(t *testing.T) {
v, _ := GetDockerIDList()
for _, id := range v {
v, err := CgroupCPUDocker(id)
if err != nil {
t.Errorf("error %v", err)
}
if v.CPU == "" {
t.Errorf("could not get CgroupCPU %v", v)
}
}
}
func TestCgroupCPUInvalidId(t *testing.T) {
_, err := CgroupCPUDocker("bad id")
if err == nil {
t.Error("Expected path does not exist error")
}
}
func TestCgroupMem(t *testing.T) {
v, _ := GetDockerIDList()
for _, id := range v {
v, err := CgroupMemDocker(id)
if err != nil {
t.Errorf("error %v", err)
}
empty := &CgroupMemStat{}
if v == empty {
t.Errorf("Could not CgroupMemStat %v", v)
}
}
}
func TestCgroupMemInvalidId(t *testing.T) {
_, err := CgroupMemDocker("bad id")
if err == nil {
t.Error("Expected path does not exist error")
}
}