summaryrefslogtreecommitdiff
path: root/tests/test_helpers/helpers.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2016-06-16 21:06:03 +0200
committerJakob Unterwurzacher2016-06-16 21:27:01 +0200
commit305e9c1045f0546967bfbd2d10f13a28b6227a76 (patch)
tree1f4790963e332c8607a66f6b021ce37c672ab62f /tests/test_helpers/helpers.go
parentc76c952c192f5378eb713f4f3435de29af0f7922 (diff)
tests: add InitFS helper
Diffstat (limited to 'tests/test_helpers/helpers.go')
-rw-r--r--tests/test_helpers/helpers.go45
1 files changed, 41 insertions, 4 deletions
diff --git a/tests/test_helpers/helpers.go b/tests/test_helpers/helpers.go
index 2f3bf0c..c006e8b 100644
--- a/tests/test_helpers/helpers.go
+++ b/tests/test_helpers/helpers.go
@@ -21,7 +21,12 @@ const DefaultCipherDir = TmpDir + "cipher/"
const GocryptfsBinary = "../../gocryptfs"
-// ResetTmpDir - delete old tmp dir, create new one, write gocryptfs.diriv
+// ResetTmpDir - delete TmpDir, create new dir tree:
+//
+// TmpDir
+// |-- DefaultPlainDir
+// *-- DefaultCipherDir
+// *-- gocryptfs.diriv
func ResetTmpDir(plaintextNames bool) {
// Try to unmount everything
@@ -59,7 +64,33 @@ func ResetTmpDir(plaintextNames bool) {
}
}
+// InitFS calls "gocryptfs -init" on a new directory in TmpDir, passing
+// "extraArgs" in addition to practical defaults.
+// The returned "dir" has NO trailing slash.
+func InitFS(t *testing.T, extraArgs ...string) string {
+ dir, err := ioutil.TempDir(TmpDir, "")
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ args := []string{"-q", "-init", "-extpass", "echo test", "-scryptn=10"}
+ args = append(args, extraArgs...)
+ args = append(args, dir)
+
+ cmd := exec.Command(GocryptfsBinary, args...)
+ cmd.Stdout = os.Stdout
+ cmd.Stderr = os.Stderr
+
+ err = cmd.Run()
+ if err != nil {
+ t.Fatalf("InitFS with args %v failed: %v", args, err)
+ }
+
+ return dir
+}
+
// Mount CIPHERDIR "c" on PLAINDIR "p"
+// Creates "p" if it does not exist.
func Mount(c string, p string, extraArgs ...string) error {
var args []string
args = append(args, extraArgs...)
@@ -68,11 +99,17 @@ func Mount(c string, p string, extraArgs ...string) error {
//args = append(args, "-d")
args = append(args, c)
args = append(args, p)
+
+ if _, err := os.Stat(p); err != nil {
+ err = os.Mkdir(p, 0777)
+ if err != nil {
+ return err
+ }
+ }
+
cmd := exec.Command(GocryptfsBinary, args...)
cmd.Stderr = os.Stderr
- if testing.Verbose() {
- cmd.Stdout = os.Stdout
- }
+ cmd.Stdout = os.Stdout
return cmd.Run()
}