diff --git a/pkg/testutil/nerdtest/requirements.go b/pkg/testutil/nerdtest/requirements.go index 3c365095b03..a5d89481203 100644 --- a/pkg/testutil/nerdtest/requirements.go +++ b/pkg/testutil/nerdtest/requirements.go @@ -171,6 +171,23 @@ var CGroup = &test.Requirement{ }, } +var CgroupsAccessible = test.Require( + CGroup, + &test.Requirement{ + Check: func(data test.Data, helpers test.Helpers) (ret bool, mess string) { + isRootLess := getTarget() == targetNerdctl && rootlessutil.IsRootless() + if isRootLess { + stdout := helpers.Capture("info", "--format", "{{ json . }}") + var dinf dockercompat.Info + err := json.Unmarshal([]byte(stdout), &dinf) + assert.NilError(helpers.T(), err, "failed to parse docker info") + return dinf.CgroupVersion == "2", "we are rootless, and cgroup version is not 2" + } + return true, "" + }, + }, +) + // Soci requires that the soci snapshotter is enabled var Soci = &test.Requirement{ Check: func(data test.Data, helpers test.Helpers) (ret bool, mess string) { diff --git a/pkg/testutil/nerdtest/requirements_other.go b/pkg/testutil/nerdtest/requirements_other.go new file mode 100644 index 00000000000..74e280670c7 --- /dev/null +++ b/pkg/testutil/nerdtest/requirements_other.go @@ -0,0 +1,29 @@ +//go:build !windows + +/* + Copyright The containerd Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package nerdtest + +import ( + "github.com/containerd/nerdctl/v2/pkg/testutil/test" +) + +var HyperV = &test.Requirement{ + Check: func(data test.Data, helpers test.Helpers) (ret bool, mess string) { + return false, "HyperV is a windows-only feature" + }, +} diff --git a/pkg/testutil/nerdtest/requirements_windows.go b/pkg/testutil/nerdtest/requirements_windows.go new file mode 100644 index 00000000000..a1155a970db --- /dev/null +++ b/pkg/testutil/nerdtest/requirements_windows.go @@ -0,0 +1,28 @@ +/* + Copyright The containerd Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package nerdtest + +import ( + "github.com/containerd/nerdctl/v2/pkg/testutil" + "github.com/containerd/nerdctl/v2/pkg/testutil/test" +) + +var HyperV = &test.Requirement{ + Check: func(data test.Data, helpers test.Helpers) (ret bool, mess string) { + return testutil.HyperVSupported(), "HyperV is not enabled, skipping test" + }, +}