(t *testing.T)
| 14 | ) |
| 15 | |
| 16 | func TestSetContainerQuota(t *testing.T) { |
| 17 | t.Parallel() |
| 18 | |
| 19 | for _, tc := range []struct { |
| 20 | Name string |
| 21 | Quota xunix.CPUQuota |
| 22 | ContainerID string |
| 23 | ExpectedFS map[string]string |
| 24 | Error string |
| 25 | }{ |
| 26 | { |
| 27 | Name: "CGroupV1", |
| 28 | Quota: xunix.CPUQuota{ |
| 29 | Quota: 150000, |
| 30 | Period: 100000, |
| 31 | CGroup: xunix.CGroupV1, |
| 32 | }, |
| 33 | ContainerID: "dummy", |
| 34 | ExpectedFS: map[string]string{ |
| 35 | "/sys/fs/cgroup/cpu,cpuacct/docker/dummy/syscont-cgroup-root/cpu.cfs_quota_us": "150000", |
| 36 | "/sys/fs/cgroup/cpu,cpuacct/docker/dummy/syscont-cgroup-root/cpu.cfs_period_us": "100000", |
| 37 | }, |
| 38 | }, |
| 39 | { |
| 40 | Name: "CGroupV2", |
| 41 | Quota: xunix.CPUQuota{ |
| 42 | Quota: 150000, |
| 43 | Period: 100000, |
| 44 | CGroup: xunix.CGroupV2, |
| 45 | }, |
| 46 | ContainerID: "dummy", |
| 47 | ExpectedFS: map[string]string{ |
| 48 | "/sys/fs/cgroup/docker/dummy/init.scope/cpu.max": "150000 100000", |
| 49 | }, |
| 50 | }, |
| 51 | { |
| 52 | Name: "CGroupV2Max", |
| 53 | Quota: xunix.CPUQuota{ |
| 54 | Quota: -1, |
| 55 | Period: 100000, |
| 56 | CGroup: xunix.CGroupV2, |
| 57 | }, |
| 58 | ContainerID: "dummy", |
| 59 | ExpectedFS: map[string]string{ |
| 60 | "/sys/fs/cgroup/docker/dummy/init.scope/cpu.max": "max 100000", |
| 61 | }, |
| 62 | }, |
| 63 | } { |
| 64 | tc := tc |
| 65 | t.Run(tc.Name, func(t *testing.T) { |
| 66 | t.Parallel() |
| 67 | tmpfs := &xunixfake.MemFS{MemMapFs: &afero.MemMapFs{}} |
| 68 | ctx := xunix.WithFS(context.Background(), tmpfs) |
| 69 | err := dockerutil.SetContainerQuota(ctx, tc.ContainerID, tc.Quota) |
| 70 | if tc.Error == "" { |
| 71 | require.NoError(t, err) |
| 72 | } else { |
| 73 | require.ErrorContains(t, err, tc.Error) |
nothing calls this directly
no test coverage detected