diff --git a/docker/docker_linux.go b/docker/docker_linux.go index a1bd1ea..25470b1 100644 --- a/docker/docker_linux.go +++ b/docker/docker_linux.go @@ -71,7 +71,10 @@ func CgroupCPU(containerid string, base string) (*cpu.CPUTimesStat, error) { } path := path.Join(base, containerid, "cpuacct.stat") - lines, _ := common.ReadLines(path) + lines, err := common.ReadLines(path) + if err != nil { + return nil, err + } // empty containerid means all cgroup if len(containerid) == 0 { containerid = "all" diff --git a/docker/docker_linux_test.go b/docker/docker_linux_test.go index 7b49d7c..48cedfb 100644 --- a/docker/docker_linux_test.go +++ b/docker/docker_linux_test.go @@ -31,6 +31,13 @@ func TestCgroupCPU(t *testing.T) { } } +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 {