aboutsummaryrefslogtreecommitdiff
path: root/tests/cli/cli_test.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2018-04-01 14:25:10 +0200
committerJakob Unterwurzacher2018-04-01 14:25:10 +0200
commit8fcd39a3b08f956edc0939c87b089b4dbb60afd6 (patch)
tree5c248ef6d83c19e6b70c53e34c049ac7182a6807 /tests/cli/cli_test.go
parent85056def909c994b66c40763f6d6c2d41c7a61d0 (diff)
main: add "-fsck" flag
The fsck operation is not yet implemented, this commits just adds the flag and improves cli flag handling.
Diffstat (limited to 'tests/cli/cli_test.go')
-rw-r--r--tests/cli/cli_test.go41
1 files changed, 38 insertions, 3 deletions
diff --git a/tests/cli/cli_test.go b/tests/cli/cli_test.go
index 9eebc5f..2cdaf37 100644
--- a/tests/cli/cli_test.go
+++ b/tests/cli/cli_test.go
@@ -18,6 +18,18 @@ import (
var testPw = []byte("test")
+// Extract the exit code from an error value that was returned from
+// exec.Run()
+func extractExitCode(err error) int {
+ if err == nil {
+ return 0
+ }
+ // OMG this is convoluted
+ err2 := err.(*exec.ExitError)
+ code := err2.Sys().(syscall.WaitStatus).ExitStatus()
+ return code
+}
+
func TestMain(m *testing.M) {
test_helpers.ResetTmpDir(false)
r := m.Run()
@@ -332,8 +344,7 @@ func TestMountPasswordIncorrect(t *testing.T) {
cDir := test_helpers.InitFS(t) // Create filesystem with password "test"
pDir := cDir + ".mnt"
err := test_helpers.Mount(cDir, pDir, false, "-extpass", "echo WRONG", "-wpanic=false")
- // vvvvvvvvvvvvvv OMG vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
- exitCode := err.(*exec.ExitError).Sys().(syscall.WaitStatus).ExitStatus()
+ exitCode := extractExitCode(err)
if exitCode != exitcodes.PasswordIncorrect {
t.Errorf("want=%d, got=%d", exitcodes.PasswordIncorrect, exitCode)
}
@@ -362,7 +373,7 @@ func TestPasswdPasswordIncorrect(t *testing.T) {
t.Fatal(err)
}
err = cmd.Wait()
- exitCode := err.(*exec.ExitError).Sys().(syscall.WaitStatus).ExitStatus()
+ exitCode := extractExitCode(err)
if exitCode != exitcodes.PasswordIncorrect {
t.Errorf("want=%d, got=%d", exitcodes.PasswordIncorrect, exitCode)
}
@@ -417,3 +428,27 @@ func TestMountBackground(t *testing.T) {
t.Fatal("timeout")
}
}
+
+// Test that "gocryptfs -init -info CIPHERDIR" returns an error to the
+// user. Only one operation flag is allowed.
+func TestMultipleOperationFlags(t *testing.T) {
+ // Test all combinations
+ opFlags := []string{"-init", "-info", "-passwd", "-fsck"}
+ for _, flag1 := range opFlags {
+ var flag2 string
+ for _, flag2 = range opFlags {
+ if flag1 == flag2 {
+ continue
+ }
+ args := []string{flag1, flag2, "/tmp"}
+ //t.Logf("testing %v", args)
+ cmd := exec.Command(test_helpers.GocryptfsBinary, args...)
+ err := cmd.Run()
+ exitCode := extractExitCode(err)
+ if exitCode != exitcodes.Usage {
+ t.Fatalf("this should have failed with code %d, but returned %d",
+ exitcodes.Usage, exitCode)
+ }
+ }
+ }
+}