-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: jason yang <[email protected]>
- Loading branch information
1 parent
0611436
commit 8656846
Showing
3 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package cgroup_test | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
"github.com/apptainer/apptheus/internal/cgroup" | ||
"github.com/opencontainers/runc/libcontainer/cgroups" | ||
"github.com/opencontainers/runc/libcontainer/configs" | ||
"github.com/stretchr/testify/mock" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type MockCgroupManager struct { | ||
mock.Mock | ||
} | ||
|
||
func (m *MockCgroupManager) Apply(pid int) error { | ||
return nil | ||
} | ||
|
||
func (m *MockCgroupManager) GetPids() ([]int, error) { | ||
return []int{}, nil | ||
} | ||
|
||
func (m *MockCgroupManager) GetAllPids() ([]int, error) { | ||
return []int{}, nil | ||
} | ||
|
||
func (m *MockCgroupManager) GetStats() (*cgroups.Stats, error) { | ||
return cgroups.NewStats(), nil | ||
} | ||
|
||
func (m *MockCgroupManager) Freeze(state configs.FreezerState) error { | ||
return nil | ||
} | ||
|
||
func (m *MockCgroupManager) Destroy() error { | ||
return nil | ||
} | ||
|
||
func (m *MockCgroupManager) Path(path string) string { | ||
return path | ||
} | ||
|
||
func (m *MockCgroupManager) Set(r *configs.Resources) error { | ||
return nil | ||
} | ||
|
||
func (m *MockCgroupManager) GetPaths() map[string]string { | ||
return map[string]string{} | ||
} | ||
|
||
func (m *MockCgroupManager) GetCgroups() (*configs.Cgroup, error) { | ||
return nil, nil | ||
} | ||
|
||
func (m *MockCgroupManager) GetFreezerState() (configs.FreezerState, error) { | ||
return "", nil | ||
} | ||
|
||
func (m *MockCgroupManager) Exists() bool { | ||
return true | ||
} | ||
|
||
func (m *MockCgroupManager) OOMKillCount() (uint64, error) { | ||
return 0, nil | ||
} | ||
|
||
func TestCgroup(t *testing.T) { | ||
cgroup := &cgroup.CGroup{ | ||
Manager: &MockCgroupManager{}, | ||
} | ||
|
||
has, err := cgroup.HasProcess() | ||
require.NoError(t, err) | ||
require.False(t, has) | ||
|
||
funcs, err := cgroup.CreateStats() | ||
require.NoError(t, err) | ||
require.NotEmpty(t, funcs) | ||
require.Len(t, funcs, 5) | ||
|
||
var buffer bytes.Buffer | ||
_, err = cgroup.Marshal(&buffer) | ||
require.NoError(t, err) | ||
} |