github.com/rumpl/bof@v23.0.0-rc.2+incompatible/integration/system/cgroupdriver_systemd_test.go (about) 1 package system 2 3 import ( 4 "context" 5 "os" 6 "testing" 7 8 "github.com/docker/docker/api/types" 9 "github.com/docker/docker/integration/internal/container" 10 "github.com/docker/docker/testutil/daemon" 11 12 "gotest.tools/v3/assert" 13 "gotest.tools/v3/skip" 14 ) 15 16 // hasSystemd checks whether the host was booted with systemd as its init 17 // system. Stolen from 18 // https://github.com/coreos/go-systemd/blob/176f85496f4e/util/util.go#L68 19 func hasSystemd() bool { 20 fi, err := os.Lstat("/run/systemd/system") 21 if err != nil { 22 return false 23 } 24 return fi.IsDir() 25 } 26 27 // TestCgroupDriverSystemdMemoryLimit checks that container 28 // memory limit can be set when using systemd cgroupdriver. 29 // https://github.com/moby/moby/issues/35123 30 func TestCgroupDriverSystemdMemoryLimit(t *testing.T) { 31 skip.If(t, testEnv.DaemonInfo.OSType == "windows") 32 skip.If(t, !hasSystemd()) 33 t.Parallel() 34 35 d := daemon.New(t) 36 c := d.NewClientT(t) 37 38 d.StartWithBusybox(t, "--exec-opt", "native.cgroupdriver=systemd", "--iptables=false") 39 defer d.Stop(t) 40 41 const mem = int64(64 * 1024 * 1024) // 64 MB 42 43 ctx := context.Background() 44 ctrID := container.Create(ctx, t, c, func(ctr *container.TestContainerConfig) { 45 ctr.HostConfig.Resources.Memory = mem 46 }) 47 defer c.ContainerRemove(ctx, ctrID, types.ContainerRemoveOptions{Force: true}) 48 49 err := c.ContainerStart(ctx, ctrID, types.ContainerStartOptions{}) 50 assert.NilError(t, err) 51 52 s, err := c.ContainerInspect(ctx, ctrID) 53 assert.NilError(t, err) 54 assert.Equal(t, s.HostConfig.Memory, mem) 55 }