Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
virtcontainers: fix unit tests
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Julio Montes committed Jan 15, 2020
1 parent 776da08 commit d042d5c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
3 changes: 2 additions & 1 deletion virtcontainers/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ var containerAnnotations = map[string]string{
func newEmptySpec() *specs.Spec {
return &specs.Spec{
Linux: &specs.Linux{
Resources: &specs.LinuxResources{},
Resources: &specs.LinuxResources{},
CgroupsPath: defaultCgroupPath,
},
Process: &specs.Process{
Capabilities: &specs.LinuxCapabilities{},
Expand Down
17 changes: 14 additions & 3 deletions virtcontainers/sandbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1454,19 +1454,22 @@ func TestSandbox_SetupSandboxCgroup(t *testing.T) {
successfulContainer.Annotations[annotations.ContainerTypeKey] = string(PodSandbox)

tests := []struct {
name string
s *Sandbox
wantErr bool
name string
s *Sandbox
wantErr bool
needRoot bool
}{
{
"New sandbox",
&Sandbox{},
true,
false,
},
{
"New sandbox, new config",
&Sandbox{config: &SandboxConfig{}},
true,
false,
},
{
"sandbox, container no sandbox type",
Expand All @@ -1475,6 +1478,7 @@ func TestSandbox_SetupSandboxCgroup(t *testing.T) {
{},
}}},
true,
false,
},
{
"sandbox, container sandbox type",
Expand All @@ -1483,6 +1487,7 @@ func TestSandbox_SetupSandboxCgroup(t *testing.T) {
sandboxContainer,
}}},
true,
false,
},
{
"sandbox, empty linux json",
Expand All @@ -1491,6 +1496,7 @@ func TestSandbox_SetupSandboxCgroup(t *testing.T) {
emptyJSONLinux,
}}},
false,
true,
},
{
"sandbox, successful config",
Expand All @@ -1499,9 +1505,14 @@ func TestSandbox_SetupSandboxCgroup(t *testing.T) {
successfulContainer,
}}},
false,
true,
},
}
for _, tt := range tests {
if tt.needRoot && os.Getuid() != 0 {
t.Skip(tt.name + "needs root")
}

t.Run(tt.name, func(t *testing.T) {
if err := tt.s.setupSandboxCgroup(); (err != nil) != tt.wantErr {
t.Errorf("Sandbox.SetupSandboxCgroupOnly() error = %v, wantErr %v", err, tt.wantErr)
Expand Down

0 comments on commit d042d5c

Please sign in to comment.