Skip to content

Commit

Permalink
chore: fix test tempdir generation (#156)
Browse files Browse the repository at this point in the history
Signed-off-by: saintube <saintube@foxmail.com>
  • Loading branch information
saintube committed May 20, 2022
1 parent 803298b commit 9f13a7b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/util/system/util_test_tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"os"
"path"
"testing"

"github.com/stretchr/testify/assert"
)

type FileTestUtil struct {
Expand All @@ -32,11 +34,15 @@ type FileTestUtil struct {

// NewFileTestUtil creates a new test util for the specified subsystem
func NewFileTestUtil(t *testing.T) *FileTestUtil {
// NOTE: When $TMPDIR is not set, `t.TempDir()` can use different base directory on Mac OS X and Linux, which may
// generates too long paths to test unix socket.
t.Setenv("TMPDIR", "/tmp")
tempDir := t.TempDir()
HostSystemInfo.IsAnolisOS = true

Conf.ProcRootDir = path.Join(tempDir, "proc")
os.MkdirAll(Conf.ProcRootDir, 0777)
err := os.MkdirAll(Conf.ProcRootDir, 0777)
assert.NoError(t, err)
Conf.CgroupRootDir = tempDir

return &FileTestUtil{TempDir: tempDir, t: t}
Expand Down

0 comments on commit 9f13a7b

Please sign in to comment.