mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-25 15:02:45 +00:00
virtcontainers: fix unit tests
fix unit test that may need a cgroup path or root to create a new cgroup Signed-off-by: Julio Montes <julio.montes@intel.com>
This commit is contained in:
parent
776da0878e
commit
d042d5c0da
@ -43,7 +43,8 @@ var containerAnnotations = map[string]string{
|
|||||||
func newEmptySpec() *specs.Spec {
|
func newEmptySpec() *specs.Spec {
|
||||||
return &specs.Spec{
|
return &specs.Spec{
|
||||||
Linux: &specs.Linux{
|
Linux: &specs.Linux{
|
||||||
Resources: &specs.LinuxResources{},
|
Resources: &specs.LinuxResources{},
|
||||||
|
CgroupsPath: defaultCgroupPath,
|
||||||
},
|
},
|
||||||
Process: &specs.Process{
|
Process: &specs.Process{
|
||||||
Capabilities: &specs.LinuxCapabilities{},
|
Capabilities: &specs.LinuxCapabilities{},
|
||||||
|
@ -1454,19 +1454,22 @@ func TestSandbox_SetupSandboxCgroup(t *testing.T) {
|
|||||||
successfulContainer.Annotations[annotations.ContainerTypeKey] = string(PodSandbox)
|
successfulContainer.Annotations[annotations.ContainerTypeKey] = string(PodSandbox)
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
s *Sandbox
|
s *Sandbox
|
||||||
wantErr bool
|
wantErr bool
|
||||||
|
needRoot bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"New sandbox",
|
"New sandbox",
|
||||||
&Sandbox{},
|
&Sandbox{},
|
||||||
true,
|
true,
|
||||||
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"New sandbox, new config",
|
"New sandbox, new config",
|
||||||
&Sandbox{config: &SandboxConfig{}},
|
&Sandbox{config: &SandboxConfig{}},
|
||||||
true,
|
true,
|
||||||
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"sandbox, container no sandbox type",
|
"sandbox, container no sandbox type",
|
||||||
@ -1475,6 +1478,7 @@ func TestSandbox_SetupSandboxCgroup(t *testing.T) {
|
|||||||
{},
|
{},
|
||||||
}}},
|
}}},
|
||||||
true,
|
true,
|
||||||
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"sandbox, container sandbox type",
|
"sandbox, container sandbox type",
|
||||||
@ -1483,6 +1487,7 @@ func TestSandbox_SetupSandboxCgroup(t *testing.T) {
|
|||||||
sandboxContainer,
|
sandboxContainer,
|
||||||
}}},
|
}}},
|
||||||
true,
|
true,
|
||||||
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"sandbox, empty linux json",
|
"sandbox, empty linux json",
|
||||||
@ -1491,6 +1496,7 @@ func TestSandbox_SetupSandboxCgroup(t *testing.T) {
|
|||||||
emptyJSONLinux,
|
emptyJSONLinux,
|
||||||
}}},
|
}}},
|
||||||
false,
|
false,
|
||||||
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"sandbox, successful config",
|
"sandbox, successful config",
|
||||||
@ -1499,9 +1505,14 @@ func TestSandbox_SetupSandboxCgroup(t *testing.T) {
|
|||||||
successfulContainer,
|
successfulContainer,
|
||||||
}}},
|
}}},
|
||||||
false,
|
false,
|
||||||
|
true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
|
if tt.needRoot && os.Getuid() != 0 {
|
||||||
|
t.Skip(tt.name + "needs root")
|
||||||
|
}
|
||||||
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
if err := tt.s.setupSandboxCgroup(); (err != nil) != tt.wantErr {
|
if err := tt.s.setupSandboxCgroup(); (err != nil) != tt.wantErr {
|
||||||
t.Errorf("Sandbox.SetupSandboxCgroupOnly() error = %v, wantErr %v", err, tt.wantErr)
|
t.Errorf("Sandbox.SetupSandboxCgroupOnly() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
|
Loading…
Reference in New Issue
Block a user