diff options
-rwxr-xr-x | test.bash | 8 | ||||
-rw-r--r-- | tests/test_helpers/helpers.go | 16 | ||||
-rw-r--r-- | tests/xattr/xattr_integration_test.go | 13 |
3 files changed, 22 insertions, 15 deletions
@@ -1,10 +1,16 @@ #!/bin/bash +if [[ -z $TMPDIR ]]; then + TMPDIR=/tmp +else + echo "Using TMPDIR=$TMPDIR" +fi + set -eu cd "$(dirname "$0")" MYNAME=$(basename "$0") -TESTDIR=/tmp/gocryptfs-test-parent +TESTDIR=$TMPDIR/gocryptfs-test-parent mkdir -p $TESTDIR LOCKFILE=$TESTDIR/$MYNAME.lock 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, "") diff --git a/tests/xattr/xattr_integration_test.go b/tests/xattr/xattr_integration_test.go index 6d4c0c3..a989060 100644 --- a/tests/xattr/xattr_integration_test.go +++ b/tests/xattr/xattr_integration_test.go @@ -16,16 +16,15 @@ import ( "github.com/rfjakob/gocryptfs/tests/test_helpers" ) -// On modern Linux distributions, /tmp may be on tmpfs, -// which does not support user xattrs. Try /var/tmp instead. -var alternateTestParentDir = "/var/tmp/gocryptfs-xattr-test-parent" - func TestMain(m *testing.M) { - if !xattrSupported(test_helpers.TmpDir) { - test_helpers.SwitchTestParentDir(alternateTestParentDir) + // On modern Linux distributions, /tmp may be on tmpfs, + // which does not support user xattrs. Try /var/tmp instead + if !xattrSupported(test_helpers.TmpDir) && os.TempDir() == "/tmp" { + fmt.Printf("Switching from /tmp to /var/tmp for xattr tests\n") + test_helpers.SwitchTMPDIR("/var/tmp") } if !xattrSupported(test_helpers.TmpDir) { - fmt.Printf("xattrs not supported on %q", test_helpers.TmpDir) + fmt.Printf("xattrs not supported on %q\n", test_helpers.TmpDir) os.Exit(1) } test_helpers.ResetTmpDir(true) |