package cgroup import "testing" func TestParseRelativeCgroupPathV1(t *testing.T) { relativePath, err := parseRelativeCgroupPathV1("testdata/cgroup_v1", "memory") if err != nil { t.Fatal(err) } if relativePath != "/kubepods/besteffort/pod30d45881-d876-4898-a212-f8c95e1b08db/b5209b0109b0fc07d889f4f7878354670c8fbc6a977201be3a6f6aa389187f1b" { t.Fatal("parse cgroup_v1 memory failed") } relativePath, err = parseRelativeCgroupPathV1("testdata/cgroup_v1", "cpuacct") if err != nil { t.Fatal(err) } if relativePath != "/kubepods/besteffort/pod30d45881-d876-4898-a212-f8c95e1b08db/b5209b0109b0fc07d889f4f7878354670c8fbc6a977201be3a6f6aa389187f1b" { t.Fatal("parse cgroup_v1 cpuacct failed") } _, err = parseRelativeCgroupPathV1("testdata/cgroup_v1", "unknown") if err == nil { t.Fatal("parse cgroup_v1 unknown failed") } } func TestParseRelativeCgroupPathV2(t *testing.T) { relativePath, err := parseRelativeCgroupPathV2("testdata/cgroup_v2_k8s") if err != nil { t.Fatal(err) } if relativePath != "/kubepods.slice/kubepods-burstable.slice/xxxxxxxxxx-1654a9da9950616391265776d0c38f1ab55c95afbc5581ed9f7ff0c370b25ebf.scope" { t.Fatal("parse cgroup_v2_k8s failed") } relativePath, err = parseRelativeCgroupPathV2("testdata/cgroup_v2_docker") if err != nil { t.Fatal(err) } if relativePath != "/system.slice/docker-1654a9da9950616391265776d0c38f1ab55c95afbc5581ed9f7ff0c370b25ebf.scope" { t.Fatal("parse cgroup_v2_docker failed") } _, err = parseRelativeCgroupPathV2("testdata/cgroup_v2_systemd") if err == nil { t.Fatal("parse cgroup_v2_systemd failed") } }