From 2f5073fea6295505caf615ae6212b283c880951d Mon Sep 17 00:00:00 2001 From: saintube Date: Thu, 19 May 2022 18:41:25 +0800 Subject: [PATCH] chore: fix test tempdir generation Signed-off-by: saintube --- pkg/util/system/util_test_tool.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/util/system/util_test_tool.go b/pkg/util/system/util_test_tool.go index 6ef96e024b..f82eeea68a 100644 --- a/pkg/util/system/util_test_tool.go +++ b/pkg/util/system/util_test_tool.go @@ -21,6 +21,8 @@ import ( "os" "path" "testing" + + "github.com/stretchr/testify/assert" ) type FileTestUtil struct { @@ -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}