mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-10 21:53:57 +08:00
16dde3befc
Switch from sync.Once to sync.OnceFunc and sync.OnceValues. Keep Root a function (rather than a variable) because godoc renders function doc better than a variable doc. Switch to using internal function root internally. Modify tests accordingly (and simplify NewIntelRdtTestUtil to fakeRoot). Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
33 lines
706 B
Go
33 lines
706 B
Go
/*
|
|
* Utility for testing Intel RDT operations.
|
|
* Creates a mock of the Intel RDT "resource control" filesystem for the duration of the test.
|
|
*/
|
|
package intelrdt
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
// fakeRoot creates a new fake root for tests and returns its path.
|
|
// Once this is called, Root() returns the same path.
|
|
func fakeRoot(t *testing.T) string {
|
|
// Assign fake intelRtdRoot value, returned by Root().
|
|
intelRdtRoot := filepath.Join(t.TempDir(), "resctrl")
|
|
if err := os.MkdirAll(intelRdtRoot, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
origRoot := root
|
|
t.Cleanup(func() {
|
|
root = origRoot
|
|
})
|
|
|
|
root = func() (string, error) {
|
|
return intelRdtRoot, nil
|
|
}
|
|
|
|
return intelRdtRoot
|
|
}
|