libct/cgroupv1: fix TestGetCgroupMounts test cases

When testing GetCgroupMounts, the map data is supposed to be obtained
from /proc/self/cgroup, but since we're mocking things, we provide
our own map.

Unfortunately, not all controllers existing in mountinfos were listed.
Also, "name=systemd" needs special handling, so add it.

The controllers added were:

 * for fedoraMountinfo case: name=systemd
 * for systemdMountinfo case: name=systemd, net_prio
 * for bedrockMountinfo case: name=systemd, net_prio, pids

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin 2020-05-19 14:41:26 -07:00
parent 0681d456fc
commit 0626c150c1
1 changed files with 35 additions and 28 deletions

View File

@ -189,46 +189,52 @@ func TestGetCgroupMounts(t *testing.T) {
mountInfo: fedoraMountinfo, mountInfo: fedoraMountinfo,
root: "/", root: "/",
subsystems: map[string]bool{ subsystems: map[string]bool{
"cpuset": false, "name=systemd": false,
"cpu": false, "cpuset": false,
"cpuacct": false, "cpu": false,
"memory": false, "cpuacct": false,
"devices": false, "memory": false,
"freezer": false, "devices": false,
"net_cls": false, "freezer": false,
"blkio": false, "net_cls": false,
"perf_event": false, "blkio": false,
"hugetlb": false, "perf_event": false,
"hugetlb": false,
}, },
}, },
{ {
mountInfo: systemdMountinfo, mountInfo: systemdMountinfo,
root: "/system.slice/docker-dc4eaa1a34ec4d593bc0125d31eea823a1d76ae483aeb1409cca80304e34da2e.scope", root: "/system.slice/docker-dc4eaa1a34ec4d593bc0125d31eea823a1d76ae483aeb1409cca80304e34da2e.scope",
subsystems: map[string]bool{ subsystems: map[string]bool{
"cpuset": false, "name=systemd": false,
"cpu": false, "cpuset": false,
"cpuacct": false, "cpu": false,
"memory": false, "cpuacct": false,
"devices": false, "memory": false,
"freezer": false, "devices": false,
"net_cls": false, "freezer": false,
"blkio": false, "net_cls": false,
"perf_event": false, "net_prio": false,
"blkio": false,
"perf_event": false,
}, },
}, },
{ {
mountInfo: bedrockMountinfo, mountInfo: bedrockMountinfo,
root: "/", root: "/",
subsystems: map[string]bool{ subsystems: map[string]bool{
"cpuset": false, "name=systemd": false,
"cpu": false, "cpuset": false,
"cpuacct": false, "cpu": false,
"memory": false, "cpuacct": false,
"devices": false, "memory": false,
"freezer": false, "devices": false,
"net_cls": false, "freezer": false,
"blkio": false, "net_cls": false,
"perf_event": false, "net_prio": false,
"blkio": false,
"perf_event": false,
"pids": false,
}, },
}, },
} }
@ -245,6 +251,7 @@ func TestGetCgroupMounts(t *testing.T) {
} }
} }
for ss := range td.subsystems { for ss := range td.subsystems {
ss = strings.TrimPrefix(ss, CgroupNamePrefix)
m, ok := cgMap[ss] m, ok := cgMap[ss]
if !ok { if !ok {
t.Fatalf("%s not found", ss) t.Fatalf("%s not found", ss)