mirror of
https://github.com/aljazceru/kata-containers.git
synced 2025-12-29 03:54:27 +01:00
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>
56 lines
962 B
Go
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)
|
|
}
|