2014-06-10 13:38:01 +08:00
|
|
|
// +build linux
|
|
|
|
|
2014-12-30 21:09:05 +08:00
|
|
|
package docker
|
2014-06-10 13:38:01 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetDockerIDList(t *testing.T) {
|
2014-06-10 13:41:14 +08:00
|
|
|
// If there is not docker environment, this test always fail.
|
|
|
|
// not tested here
|
|
|
|
/*
|
2014-08-16 01:18:30 +08:00
|
|
|
_, err := GetDockerIDList()
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("error %v", err)
|
|
|
|
}
|
|
|
|
*/
|
2014-06-10 13:38:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-11 02:36:19 +08:00
|
|
|
func TestCgroupCPUInvalidId(t *testing.T) {
|
|
|
|
_, err := CgroupCPUDocker("bad id")
|
|
|
|
if err == nil {
|
|
|
|
t.Error("Expected path does not exist error")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-10 13:38:01 +08:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
Don't ignore err when getting CgroupMemDocker stats
Fixes panic: runtime error: index out of range
goroutine 10 [running]:
testing.func·006()
/usr/local/go/src/testing/testing.go:441 +0x181
github.com/shirou/gopsutil/docker.CgroupMem(0x586b30, 0x6, 0x5a87d0, 0x1c, 0x0, 0x0, 0x0)
/home/jwilder/go/src/github.com/shirou/gopsutil/docker/docker_linux.go:119 +0xf48
github.com/shirou/gopsutil/docker.CgroupMemDocker(0x586b30, 0x6, 0x0, 0x0, 0x0)
/home/jwilder/go/src/github.com/shirou/gopsutil/docker/docker_linux.go:184 +0x57
If the ID passed to the CGroupMemDocker does not exist, you can get
a panic at runtime. This can happen when a container exits before
calling the func.
2015-02-11 02:20:45 +08:00
|
|
|
|
|
|
|
func TestCgroupMemInvalidId(t *testing.T) {
|
|
|
|
_, err := CgroupMemDocker("bad id")
|
|
|
|
if err == nil {
|
|
|
|
t.Error("Expected path does not exist error")
|
|
|
|
}
|
|
|
|
}
|