Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix test tempdir generation #156

Merged
merged 1 commit into from
May 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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