diff --git a/docker/docker_linux.go b/docker/docker_linux.go index 0f783d7..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" @@ -109,7 +112,10 @@ func CgroupMem(containerid string, base string) (*CgroupMemStat, error) { if len(containerid) == 0 { containerid = "all" } - lines, _ := common.ReadLines(path) + lines, err := common.ReadLines(path) + if err != nil { + return nil, err + } ret := &CgroupMemStat{ContainerID: containerid} for _, line := range lines { fields := strings.Split(line, " ") diff --git a/docker/docker_linux_test.go b/docker/docker_linux_test.go index d5504f7..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 { @@ -44,3 +51,10 @@ func TestCgroupMem(t *testing.T) { } } } + +func TestCgroupMemInvalidId(t *testing.T) { + _, err := CgroupMemDocker("bad id") + if err == nil { + t.Error("Expected path does not exist error") + } +}