summaryrefslogtreecommitdiff
path: root/tests/test_helpers/helpers.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2016-06-30 00:57:14 +0200
committerJakob Unterwurzacher2016-06-30 00:57:14 +0200
commit02b6d3067d502bcc063965a5a9d75aa693125e1b (patch)
tree6b6df8eeac9017bc985de20fa3f8cf22466bad66 /tests/test_helpers/helpers.go
parentffc000943b33724b1df0db69af35123abb1331a8 (diff)
test: split up integration_tests
...into "matrix" and "normal". Also: * Make running multiple packages in parallel safe, see http://stackoverflow.com/questions/23715302/go-how-to-run-tests-for-multiple-packages * Don't depent on test_helper.TmpDir and friends to have a terminating slash
Diffstat (limited to 'tests/test_helpers/helpers.go')
-rw-r--r--tests/test_helpers/helpers.go71
1 files changed, 38 insertions, 33 deletions
diff --git a/tests/test_helpers/helpers.go b/tests/test_helpers/helpers.go
index 88ef039..a6c2b7d 100644
--- a/tests/test_helpers/helpers.go
+++ b/tests/test_helpers/helpers.go
@@ -10,17 +10,31 @@ import (
"path/filepath"
"syscall"
"testing"
+ "time"
"github.com/rfjakob/gocryptfs/internal/nametransform"
)
-// Note: the code assumes that all have a trailing slash
-const TmpDir = "/tmp/gocryptfs_main_test/"
-const DefaultPlainDir = TmpDir + "plain/"
-const DefaultCipherDir = TmpDir + "cipher/"
-
+const testParentDir = "/tmp/gocryptfs-test-parent"
const GocryptfsBinary = "../../gocryptfs"
+// "go test" runs package tests in parallel! We must create a unique TmpDir on
+// startup or the tests will interfere horribly
+var TmpDir string
+var DefaultPlainDir string
+var DefaultCipherDir string
+
+func init() {
+ os.MkdirAll(testParentDir, 0700)
+ var err error
+ TmpDir, err = ioutil.TempDir(testParentDir, "")
+ if err != nil {
+ panic(err)
+ }
+ DefaultPlainDir = TmpDir + "/default-plain"
+ DefaultCipherDir = TmpDir + "/default-cipher"
+}
+
// ResetTmpDir - delete TmpDir, create new dir tree:
//
// TmpDir
@@ -28,38 +42,31 @@ const GocryptfsBinary = "../../gocryptfs"
// *-- DefaultCipherDir
// *-- gocryptfs.diriv
func ResetTmpDir(plaintextNames bool) {
-
- // Try to unmount everything
+ // Try to unmount and delete everything
entries, err := ioutil.ReadDir(TmpDir)
if err == nil {
for _, e := range entries {
- fu := exec.Command("fusermount", "-z", "-u", filepath.Join(TmpDir, e.Name()))
- fu.Run()
+ d := filepath.Join(TmpDir, e.Name())
+ err = os.Remove(d)
+ if err != nil {
+ fu := exec.Command("fusermount", "-z", "-u", d)
+ fu.Run()
+ os.RemoveAll(d)
+ }
}
}
-
- err = os.RemoveAll(TmpDir)
+ err = os.Mkdir(DefaultPlainDir, 0700)
if err != nil {
- fmt.Println("resetTmpDir: RemoveAll:" + err.Error())
- os.Exit(1)
+ panic(err)
}
-
- err = os.MkdirAll(DefaultPlainDir, 0777)
+ err = os.Mkdir(DefaultCipherDir, 0700)
if err != nil {
- fmt.Println(err)
- os.Exit(1)
- }
-
- err = os.MkdirAll(DefaultCipherDir, 0777)
- if err != nil {
- fmt.Println(err)
- os.Exit(1)
+ panic(err)
}
if !plaintextNames {
err = nametransform.WriteDirIV(DefaultCipherDir)
if err != nil {
- fmt.Println(err)
- os.Exit(1)
+ panic(err)
}
}
}
@@ -73,7 +80,6 @@ func InitFS(t *testing.T, extraArgs ...string) string {
if err != nil {
t.Fatal(err)
}
-
args := []string{"-q", "-init", "-extpass", "echo test", "-scryptn=10"}
args = append(args, extraArgs...)
args = append(args, dir)
@@ -95,7 +101,7 @@ func InitFS(t *testing.T, extraArgs ...string) string {
func Mount(c string, p string, showOutput bool, extraArgs ...string) error {
var args []string
args = append(args, extraArgs...)
- args = append(args, "-nosyslog", "-q", "-wpanic")
+ args = append(args, "-q", "-wpanic")
//args = append(args, "-fusedebug")
//args = append(args, "-d")
args = append(args, c)
@@ -142,7 +148,9 @@ func Unmount(p string) error {
err := fu.Run()
if err != nil {
fmt.Println(err)
+ panic(err)
}
+ time.Sleep(10 * time.Millisecond)
return err
}
@@ -184,7 +192,7 @@ func VerifySize(t *testing.T, path string, want int) {
// Create and delete a directory
func TestMkdirRmdir(t *testing.T, plainDir string) {
- dir := plainDir + "dir1"
+ dir := plainDir + "/dir1"
err := os.Mkdir(dir, 0777)
if err != nil {
t.Fatal(err)
@@ -231,8 +239,8 @@ func TestMkdirRmdir(t *testing.T, plainDir string) {
// Create and rename a file
func TestRename(t *testing.T, plainDir string) {
- file1 := plainDir + "rename1"
- file2 := plainDir + "rename2"
+ file1 := plainDir + "/rename1"
+ file2 := plainDir + "/rename2"
err := ioutil.WriteFile(file1, []byte("content"), 0777)
if err != nil {
t.Fatal(err)
@@ -247,14 +255,12 @@ func TestRename(t *testing.T, plainDir string) {
// verifyExistence - check in 3 ways that "path" exists:
// stat, open, readdir
func VerifyExistence(path string) bool {
-
// Check that file can be stated
_, err := os.Stat(path)
if err != nil {
//t.Log(err)
return false
}
-
// Check that file can be opened
fd, err := os.Open(path)
if err != nil {
@@ -262,7 +268,6 @@ func VerifyExistence(path string) bool {
return false
}
fd.Close()
-
// Check that file shows up in directory listing
dir := filepath.Dir(path)
name := filepath.Base(path)