From d7fb3543fca18f94e4742552f6d84721c02ae7a2 Mon Sep 17 00:00:00 2001 From: "R.B. Boyer" <4903+rboyer@users.noreply.github.com> Date: Thu, 24 Jun 2021 15:46:23 -0500 Subject: [PATCH] sdk: Stop making a special /tmp/consul-test directory for testutil.TempFile and testutil.TempDir (#10494) --- sdk/testutil/io.go | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/sdk/testutil/io.go b/sdk/testutil/io.go index a2447dd4c8..b46425a50a 100644 --- a/sdk/testutil/io.go +++ b/sdk/testutil/io.go @@ -1,34 +1,12 @@ package testutil import ( - "fmt" "io/ioutil" "os" "strings" "testing" ) -// tmpdir is the base directory for all temporary directories -// and files created with TempDir and TempFile. This could be -// achieved by setting a system environment variable but then -// the test execution would depend on whether or not the -// environment variable is set. -// -// On macOS the temp base directory is quite long and that -// triggers a problem with some tests that bind to UNIX sockets -// where the filename seems to be too long. Using a shorter name -// fixes this and makes the paths more readable. -// -// It also provides a single base directory for cleanup. -var tmpdir = "/tmp/consul-test" - -func init() { - if err := os.MkdirAll(tmpdir, 0755); err != nil { - fmt.Printf("Cannot create %s. Reverting to /tmp\n", tmpdir) - tmpdir = "/tmp" - } -} - var noCleanup = strings.ToLower(os.Getenv("TEST_NOCLEANUP")) == "true" // TempDir creates a temporary directory within tmpdir with the name 'testname-name'. @@ -41,7 +19,7 @@ func TempDir(t testing.TB, name string) string { } name = t.Name() + "-" + name name = strings.Replace(name, "/", "_", -1) - d, err := ioutil.TempDir(tmpdir, name) + d, err := ioutil.TempDir("", name) if err != nil { t.Fatalf("err: %s", err) } @@ -67,7 +45,7 @@ func TempFile(t testing.TB, name string) *os.File { } name = t.Name() + "-" + name name = strings.Replace(name, "/", "_", -1) - f, err := ioutil.TempFile(tmpdir, name) + f, err := ioutil.TempFile("", name) if err != nil { t.Fatalf("err: %s", err) }