summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJakob Unterwurzacher2016-07-11 20:31:36 +0200
committerJakob Unterwurzacher2016-07-11 20:41:16 +0200
commit1c54fcd04bbf274dd5d4300e433bdcb1bb32e1ce (patch)
treedb467866f9435cb493f1ee321f54b37032aec7a3 /tests
parent621cbad5e139a0bdbfde598d3c8ce82b0d43af66 (diff)
tests: use unmount wrapper in ResetTmpDir
This should make it work on OSX. Also, split unmount into two functions. Depending on what you want, * UnmountErr returns the resulting error * UnmountPanic panics if the error was not nil
Diffstat (limited to 'tests')
-rw-r--r--tests/example_filesystems/example_filesystems_test.go19
-rw-r--r--tests/matrix/matrix_test.go2
-rw-r--r--tests/normal/cli_test.go4
-rw-r--r--tests/plaintextnames/plaintextnames_test.go2
-rw-r--r--tests/test_helpers/helpers.go34
5 files changed, 36 insertions, 25 deletions
diff --git a/tests/example_filesystems/example_filesystems_test.go b/tests/example_filesystems/example_filesystems_test.go
index 13aa941..e38d3e6 100644
--- a/tests/example_filesystems/example_filesystems_test.go
+++ b/tests/example_filesystems/example_filesystems_test.go
@@ -7,6 +7,8 @@ package example_filesystems
// "-openssl=true".
import (
+ "flag"
+ "fmt"
"os"
"testing"
@@ -18,7 +20,12 @@ const statusTxtContent = "It works!\n"
var opensslOpt string
func TestMain(m *testing.M) {
+ // Make "testing.Verbose()" return the correct value
+ flag.Parse()
for _, opensslOpt = range []string{"-openssl=false", "-openssl=true"} {
+ if testing.Verbose() {
+ fmt.Printf("TestMain: testing with %q\n", opensslOpt)
+ }
test_helpers.ResetTmpDir(true)
r := m.Run()
if r != 0 {
@@ -80,12 +87,12 @@ func TestExampleFSv07(t *testing.T) {
}
test_helpers.MountOrFatal(t, cDir, pDir, "-extpass", "echo test", opensslOpt)
checkExampleFS(t, pDir, true)
- test_helpers.Unmount(pDir)
+ test_helpers.UnmountPanic(pDir)
test_helpers.MountOrFatal(t, cDir, pDir, "-masterkey",
"ed7f6d83-40cce86c-0e7d79c2-a9438710-575221bf-30a0eb60-2821fa8f-7f3123bf",
opensslOpt)
checkExampleFS(t, pDir, true)
- test_helpers.Unmount(pDir)
+ test_helpers.UnmountPanic(pDir)
}
// gocryptfs v0.7 filesystem created with "-plaintextnames"
@@ -95,7 +102,7 @@ func TestExampleFSv07PlaintextNames(t *testing.T) {
test_helpers.MountOrFatal(t, cDir, pDir, "-extpass", "echo test", opensslOpt)
checkExampleFS(t, pDir, true)
- test_helpers.Unmount(pDir)
+ test_helpers.UnmountPanic(pDir)
// The actual unmount takes some time, this causes weird problems. Just don't
// reuse the mountpoint.
pDir = pDir + ".2"
@@ -103,7 +110,7 @@ func TestExampleFSv07PlaintextNames(t *testing.T) {
"6d96397b-585631e1-c7cba69d-61e738b6-4d5ad2c2-e21f0fb3-52f60d3a-b08526f7",
opensslOpt)
checkExampleFS(t, pDir, true)
- test_helpers.Unmount(pDir)
+ test_helpers.UnmountPanic(pDir)
}
// Test example_filesystems/v0.9
@@ -117,11 +124,11 @@ func TestExampleFSv09(t *testing.T) {
}
test_helpers.MountOrFatal(t, cDir, pDir, "-extpass", "echo test", opensslOpt)
checkExampleFSLongnames(t, pDir)
- test_helpers.Unmount(pDir)
+ test_helpers.UnmountPanic(pDir)
pDir = pDir + ".2"
test_helpers.MountOrFatal(t, cDir, pDir, "-masterkey",
"1cafe3f4-bc316466-2214c47c-ecd89bf3-4e078fe4-f5faeea7-8b7cab02-884f5e1c",
opensslOpt)
checkExampleFSLongnames(t, pDir)
- test_helpers.Unmount(pDir)
+ test_helpers.UnmountPanic(pDir)
}
diff --git a/tests/matrix/matrix_test.go b/tests/matrix/matrix_test.go
index b73a0cf..2bd5b9f 100644
--- a/tests/matrix/matrix_test.go
+++ b/tests/matrix/matrix_test.go
@@ -45,7 +45,7 @@ func TestMain(m *testing.M) {
opts = append(opts, fmt.Sprintf("-plaintextnames=%v", plaintextnames))
test_helpers.MountOrExit(test_helpers.DefaultCipherDir, test_helpers.DefaultPlainDir, opts...)
r := m.Run()
- test_helpers.Unmount(test_helpers.DefaultPlainDir)
+ test_helpers.UnmountPanic(test_helpers.DefaultPlainDir)
if r != 0 {
os.Exit(r)
}
diff --git a/tests/normal/cli_test.go b/tests/normal/cli_test.go
index 4c634f2..ed3111b 100644
--- a/tests/normal/cli_test.go
+++ b/tests/normal/cli_test.go
@@ -17,7 +17,7 @@ func TestMain(m *testing.M) {
test_helpers.ResetTmpDir(false)
test_helpers.MountOrExit(test_helpers.DefaultCipherDir, test_helpers.DefaultPlainDir, "--zerokey")
r := m.Run()
- test_helpers.Unmount(test_helpers.DefaultPlainDir)
+ test_helpers.UnmountPanic(test_helpers.DefaultPlainDir)
os.Exit(r)
}
@@ -91,7 +91,7 @@ func TestRo(t *testing.T) {
dir := test_helpers.InitFS(t)
mnt := dir + ".mnt"
test_helpers.MountOrFatal(t, dir, mnt, "-ro", "-extpass=echo test")
- defer test_helpers.Unmount(mnt)
+ defer test_helpers.UnmountPanic(mnt)
file := mnt + "/file"
err := os.Mkdir(file, 0777)
diff --git a/tests/plaintextnames/plaintextnames_test.go b/tests/plaintextnames/plaintextnames_test.go
index 6c6d272..3523c25 100644
--- a/tests/plaintextnames/plaintextnames_test.go
+++ b/tests/plaintextnames/plaintextnames_test.go
@@ -21,7 +21,7 @@ func TestMain(m *testing.M) {
pDir = cDir + ".mnt"
test_helpers.MountOrExit(cDir, pDir, "-extpass", "echo test")
r := m.Run()
- test_helpers.Unmount(pDir)
+ test_helpers.UnmountPanic(pDir)
os.Exit(r)
}
diff --git a/tests/test_helpers/helpers.go b/tests/test_helpers/helpers.go
index d2c12a9..b42adcd 100644
--- a/tests/test_helpers/helpers.go
+++ b/tests/test_helpers/helpers.go
@@ -11,7 +11,6 @@ import (
"runtime"
"syscall"
"testing"
- "time"
"github.com/rfjakob/gocryptfs/internal/nametransform"
)
@@ -50,9 +49,11 @@ func ResetTmpDir(plaintextNames bool) {
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)
+ UnmountErr(d)
+ err = os.RemoveAll(d)
+ if err != nil {
+ panic(err)
+ }
}
}
}
@@ -141,23 +142,26 @@ func MountOrFatal(t *testing.T, c string, p string, extraArgs ...string) {
}
}
-// Unmount PLAINDIR "p"
-func Unmount(p string) error {
+// UnmountPanic tries to umount "dir" and panics on error.
+func UnmountPanic(dir string) {
+ err := UnmountErr(dir)
+ if err != nil {
+ fmt.Println(err)
+ panic(err)
+ }
+}
+
+// UnmountError tries to unmount "dir" and returns the resulting error.
+func UnmountErr(dir string) error {
var cmd *exec.Cmd
if runtime.GOOS == "darwin" {
- cmd = exec.Command("umount", p)
+ cmd = exec.Command("umount", dir)
} else {
- cmd = exec.Command("fusermount", "-u", "-z", p)
+ cmd = exec.Command("fusermount", "-u", "-z", dir)
}
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
- err := cmd.Run()
- if err != nil {
- fmt.Println(err)
- panic(err)
- }
- time.Sleep(10 * time.Millisecond)
- return err
+ return cmd.Run()
}
// Return md5 string for file "filename"