mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 22:37:14 +08:00
e692886563
1. Dismantle and remove struct cgroupData. It contained three unrelated
entities (cgroup paths, pid, and resources), and made the code
harder to read. Most importantly, though, it is not needed.
Now, subsystems' Apply methods take path, resources, and pid.
To a reviewer -- the core of the changes is in fs.go and paths.go,
the rest of it is adapting to the new signatures and related test
changes.
2. Dismantle and remove struct cgroupTestUtil. This is a followup
to the previous item -- since cgroupData is gone, there is nothing
to hold in cgroupTestUtil. The change itself is very small (see
util_test.go), but this patch is big because of it -- mostly
because we had to replace helper.cgroup.Resources with
&config.Resources{}.
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
40 lines
885 B
Go
40 lines
885 B
Go
/*
|
|
Utility for testing cgroup operations.
|
|
|
|
Creates a mock of the cgroup filesystem for the duration of the test.
|
|
*/
|
|
package fs
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/opencontainers/runc/libcontainer/cgroups"
|
|
)
|
|
|
|
func init() {
|
|
cgroups.TestMode = true
|
|
}
|
|
|
|
// tempDir creates a new test directory for the specified subsystem.
|
|
func tempDir(t *testing.T, subsystem string) string {
|
|
path := filepath.Join(t.TempDir(), subsystem)
|
|
// Ensure the full mock cgroup path exists.
|
|
if err := os.Mkdir(path, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return path
|
|
}
|
|
|
|
// writeFileContents writes the specified contents on the mock of the specified
|
|
// cgroup files.
|
|
func writeFileContents(t *testing.T, path string, fileContents map[string]string) {
|
|
for file, contents := range fileContents {
|
|
err := cgroups.WriteFile(path, file, contents)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
}
|