diff options
| author | AN Long <aisk1988@gmail.com> | 2025-08-12 14:06:53 +0000 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2025-08-29 09:56:10 -0700 |
| commit | ba9e1ddccfe55e711ac3987f74109393dfb736af (patch) | |
| tree | d1b52c85cb7d885b2f870cba8e1b404b24b877af /src/testing/testing.go | |
| parent | 9f6936b8da81672cebcfa7ac3d6edddf9f1a5d65 (diff) | |
| download | go-ba9e1ddccfe55e711ac3987f74109393dfb736af.tar.xz | |
testing: allow specify temp dir by GOTMPDIR environment variable
Allow change the default temp directory returned by t.TempDir()
by environment variable GOTMPDIR.
Fixes #61585
Change-Id: Iba969bb02744e106cf15d80e0eda0245a55fc290
GitHub-Last-Rev: aeacea00952b11990b49a0fde6a0ce4fe910b777
GitHub-Pull-Request: golang/go#74844
Reviewed-on: https://go-review.googlesource.com/c/go/+/692455
Reviewed-by: Damien Neil <dneil@google.com>
Auto-Submit: Sean Liao <sean@liao.dev>
Reviewed-by: Sean Liao <sean@liao.dev>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Diffstat (limited to 'src/testing/testing.go')
| -rw-r--r-- | src/testing/testing.go | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/testing/testing.go b/src/testing/testing.go index 3475bfca4a..2f0206b0a4 100644 --- a/src/testing/testing.go +++ b/src/testing/testing.go @@ -1318,6 +1318,8 @@ func (c *common) Cleanup(f func()) { // all its subtests complete. // Each subsequent call to TempDir returns a unique directory; // if the directory creation fails, TempDir terminates the test by calling Fatal. +// If the environment variable GOTMPDIR is set, the temporary directory will +// be created somewhere beneath it. func (c *common) TempDir() string { c.checkFuzzFn("TempDir") // Use a single parent directory for all the temporary directories @@ -1362,7 +1364,7 @@ func (c *common) TempDir() string { return -1 } pattern = strings.Map(mapper, pattern) - c.tempDir, c.tempDirErr = os.MkdirTemp("", pattern) + c.tempDir, c.tempDirErr = os.MkdirTemp(os.Getenv("GOTMPDIR"), pattern) if c.tempDirErr == nil { c.Cleanup(func() { if err := removeAll(c.tempDir); err != nil { |
