MCPcopy Create free account
hub / github.com/coder/envbox / TestSetContainerQuota

Function TestSetContainerQuota

dockerutil/container_test.go:16–82  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func 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)

Callers

nothing calls this directly

Calls 3

WithFSFunction · 0.92
SetContainerQuotaFunction · 0.92
RunMethod · 0.45

Tested by

no test coverage detected