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.
This commit is contained in:
Jakob Unterwurzacher 2018-10-10 22:24:20 +02:00
parent e4f1a32a9a
commit 5a1ebdb4f7
3 changed files with 22 additions and 15 deletions

View File

@ -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

View File

@ -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, "")

View File

@ -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)