Files
kata-containers/virtcontainers/pkg/cgroups/manager_test.go
Julio Montes ea82922a54 virtcontainers/pkg/cgroups: implement cgroup manager
cgroup manager is in charge to create and setup cgroups for
virtual containers, for example it adds /dev/kvm and
/dev/vhost-net to the list of cgroup devices in order to have
virtual containers working.

fixes #2438
fixes #2419

Signed-off-by: Julio Montes <julio.montes@intel.com>
2020-02-21 02:54:34 +00:00

56 lines
962 B
Go

// Copyright (c) 2020 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0
//
package cgroups
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestEnableSystemdCgroup(t *testing.T) {
assert := assert.New(t)
orgSystemdCgroup := systemdCgroup
defer func() {
systemdCgroup = orgSystemdCgroup
}()
useSystemdCgroup := UseSystemdCgroup()
if systemdCgroup != nil {
assert.Equal(*systemdCgroup, useSystemdCgroup)
} else {
assert.False(useSystemdCgroup)
}
EnableSystemdCgroup()
assert.True(UseSystemdCgroup())
}
func TestNew(t *testing.T) {
assert := assert.New(t)
useSystemdCgroup := false
orgSystemdCgroup := systemdCgroup
defer func() {
systemdCgroup = orgSystemdCgroup
}()
systemdCgroup = &useSystemdCgroup
c := &Config{
Cgroups: nil,
CgroupPath: "",
}
mgr, err := New(c)
assert.NoError(err)
assert.NotNil(mgr.mgr)
useSystemdCgroup = true
mgr, err = New(c)
assert.Error(err)
assert.Nil(mgr)
}