tests: split testParentDir by UID

When we run tests as root, they will leave root-owned files
in testParentDir, which causes trouble when we run tests as
a normal user later on. Split by UID.
This commit is contained in:
Jakob Unterwurzacher 2019-05-01 13:06:52 +02:00
parent 41dfbe67f8
commit 3ac9872230
3 changed files with 5 additions and 4 deletions

View File

@ -16,7 +16,8 @@ func TestMain(m *testing.M) {
fmt.Println(err) fmt.Println(err)
os.Exit(1) os.Exit(1)
} }
parent := "/tmp/gocryptfs-test-parent" // Cannot import test_helpers because of import cycle
parent := fmt.Sprintf("/tmp/gocryptfs-test-parent-%d", os.Getuid())
err = os.MkdirAll(parent, 0700) err = os.MkdirAll(parent, 0700)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)

View File

@ -10,7 +10,7 @@ set -eu
cd "$(dirname "$0")" cd "$(dirname "$0")"
MYNAME=$(basename "$0") MYNAME=$(basename "$0")
TESTDIR=$TMPDIR/gocryptfs-test-parent TESTDIR=$TMPDIR/gocryptfs-test-parent-$UID
mkdir -p $TESTDIR mkdir -p $TESTDIR
LOCKFILE=$TESTDIR/$MYNAME.lock LOCKFILE=$TESTDIR/$MYNAME.lock

View File

@ -59,8 +59,8 @@ func init() {
func doInit() { func doInit() {
X255 = string(bytes.Repeat([]byte("X"), 255)) X255 = string(bytes.Repeat([]byte("X"), 255))
MountInfo = make(map[string]mountInfo) MountInfo = make(map[string]mountInfo)
// Something like /tmp/gocryptfs-test-parent-1234
testParentDir := os.TempDir() + "/gocryptfs-test-parent" testParentDir := fmt.Sprintf("%s/gocryptfs-test-parent-%d", os.TempDir(), os.Getuid())
os.MkdirAll(testParentDir, 0700) os.MkdirAll(testParentDir, 0700)
var err error var err error
TmpDir, err = ioutil.TempDir(testParentDir, "") TmpDir, err = ioutil.TempDir(testParentDir, "")