diff options
author | Jakob Unterwurzacher | 2018-10-10 22:24:20 +0200 |
---|---|---|
committer | Jakob Unterwurzacher | 2018-10-10 22:24:20 +0200 |
commit | 5a1ebdb4f7449759656a1344d3c63ba3798e2782 (patch) | |
tree | a551606ba0c53521fee1b93c71ee268682493644 /tests/test_helpers/helpers.go | |
parent | e4f1a32a9a109805107fc0655006f2eedf75c52c (diff) |
tests: respect TMPDIR if set
Setting TMPDIR now allows to run the tests against
a directory of your choice, making it easier to test
different filesystems.
Diffstat (limited to 'tests/test_helpers/helpers.go')
-rw-r--r-- | tests/test_helpers/helpers.go | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/tests/test_helpers/helpers.go b/tests/test_helpers/helpers.go index b36056e..26eb60c 100644 --- a/tests/test_helpers/helpers.go +++ b/tests/test_helpers/helpers.go @@ -21,8 +21,9 @@ import ( "github.com/rfjakob/gocryptfs/internal/nametransform" ) -// TmpDir will be created inside this directory -var testParentDir = "/tmp/gocryptfs-test-parent" +// TmpDir will be created inside this directory, set in init() to +// $TMPDIR/gocryptfs-test-parent . +var testParentDir = "" // GocryptfsBinary is the assumed path to the gocryptfs build. const GocryptfsBinary = "../../gocryptfs" @@ -43,11 +44,11 @@ var DefaultPlainDir string // DefaultCipherDir is TmpDir + "/default-cipher" var DefaultCipherDir string -// SwitchTestParentDir changes testParentDir. This is used when you want -// to perform tests on a special filesystem. For example, the xattr tests -// cannot run on tmpfs and use /var/tmp instead of /tmp. -func SwitchTestParentDir(newDir string) { - testParentDir = newDir +// SwitchTMPDIR changes TMPDIR and hence the directory the test are performed in. +// This is used when you want to perform tests on a special filesystem. The +// xattr tests cannot run on tmpfs and use /var/tmp instead of /tmp. +func SwitchTMPDIR(newDir string) { + os.Setenv("TMPDIR", newDir) doInit() } @@ -58,6 +59,7 @@ func init() { func doInit() { X255 = string(bytes.Repeat([]byte("X"), 255)) + testParentDir := os.TempDir() + "/gocryptfs-test-parent" os.MkdirAll(testParentDir, 0700) var err error TmpDir, err = ioutil.TempDir(testParentDir, "") |