From cf667aa7ee1cceb20ef00704f20642e91331ce5e Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 4 Jun 2025 14:24:45 +0200 Subject: [PATCH] pkg/oci: add basic test for WithParentCgroupDevices It was not used in the code, and had no coverage, so adding some basic unit-tests. Signed-off-by: Sebastiaan van Stijn --- pkg/oci/spec_opts_test.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/pkg/oci/spec_opts_test.go b/pkg/oci/spec_opts_test.go index 876d90cf01..0bb01677b5 100644 --- a/pkg/oci/spec_opts_test.go +++ b/pkg/oci/spec_opts_test.go @@ -830,6 +830,32 @@ func TestWithoutMounts(t *testing.T) { } } +func TestWithParentCgroupDevices(t *testing.T) { + t.Parallel() + + // TODO(thaJeztah): WithParentCgroupDevices should probably be a no-op if the Spec is non-Linux. + for name, spec := range emptySpecs { + t.Run(name, func(t *testing.T) { + err := WithParentCgroupDevices(context.Background(), nil, nil, &spec) + assert.NoError(t, err) + assert.Nil(t, spec.Linux.Resources.Devices) + }) + } + + t.Run("reset existing", func(t *testing.T) { + s := Spec{ + Linux: &specs.Linux{ + Resources: &specs.LinuxResources{ + Devices: []specs.LinuxDeviceCgroup{{Allow: true, Access: rwm}}, + }, + }, + } + err := WithParentCgroupDevices(context.Background(), nil, nil, &s) + assert.NoError(t, err) + assert.Nil(t, s.Linux.Resources.Devices) + }) +} + func TestWithWindowsDevice(t *testing.T) { testcases := []struct { name string