Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new requirements (HyperV, CgroupsAccessible) #3592

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions pkg/testutil/nerdtest/requirements.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
29 changes: 29 additions & 0 deletions pkg/testutil/nerdtest/requirements_other.go
Original file line number Diff line number Diff line change
@@ -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"
},
}
28 changes: 28 additions & 0 deletions pkg/testutil/nerdtest/requirements_windows.go
Original file line number Diff line number Diff line change
@@ -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"
},
}