aboutsummaryrefslogtreecommitdiff
path: root/tests/test_helpers
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/test_helpers
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/test_helpers')
-rw-r--r--tests/test_helpers/helpers.go34
1 files changed, 19 insertions, 15 deletions
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"