MCPcopy Index your code
hub / github.com/coder/envbox / TestReadCPUQuota

Function TestReadCPUQuota

xunix/sys_test.go:16–87  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestReadCPUQuota(t *testing.T) {
17 t.Parallel()
18
19 for _, tc := range []struct {
20 Name string
21 Subpath string
22 FS map[string]string
23 Expected xunix.CPUQuota
24 Error string
25 }{
26 {
27 Name: "CGroupV1",
28 Subpath: "docker/dummy",
29 FS: map[string]string{
30 xunix.CPUQuotaPathCGroupV1: "150000\n",
31 xunix.CPUPeriodPathCGroupV1: "100000\n",
32 },
33 Expected: xunix.CPUQuota{Quota: 150000, Period: 100000, CGroup: xunix.CGroupV1},
34 },
35 {
36 Name: "CGroupV1_Invalid",
37 Subpath: "docker/dummy",
38 FS: map[string]string{
39 xunix.CPUQuotaPathCGroupV1: "100000\n",
40 xunix.CPUPeriodPathCGroupV1: "invalid\n",
41 },
42 Error: `period invalid not an int`,
43 },
44 {
45 Name: "CGroupV2",
46 Subpath: "docker/dummy",
47 FS: map[string]string{
48 "/proc/self/cgroup": "0::/kubepods/pod/container\n",
49 "/sys/fs/cgroup/kubepods/pod/container/cpu.max": "150000 100000\n",
50 },
51 Expected: xunix.CPUQuota{Quota: 150000, Period: 100000, CGroup: xunix.CGroupV2},
52 },
53 {
54 Name: "CGroupV2_Max",
55 Subpath: "docker/dummy",
56 FS: map[string]string{
57 "/proc/self/cgroup": "0::/kubepods/pod/container\n",
58 "/sys/fs/cgroup/kubepods/pod/container/cpu.max": "max 100000\n",
59 },
60 Expected: xunix.CPUQuota{Quota: -1, Period: 100000, CGroup: xunix.CGroupV2},
61 },
62 {
63 Name: "Empty",
64 FS: map[string]string{},
65 Error: "file does not exist",
66 },
67 } {
68 tc := tc
69 t.Run(tc.Name, func(t *testing.T) {
70 t.Parallel()
71 log := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true})
72 tmpfs := &xunixfake.MemFS{MemMapFs: &afero.MemMapFs{}}
73 ctx := xunix.WithFS(context.Background(), tmpfs)

Callers

nothing calls this directly

Calls 3

WithFSFunction · 0.92
ReadCPUQuotaFunction · 0.92
RunMethod · 0.45

Tested by

no test coverage detected