summaryrefslogtreecommitdiff
path: root/cli_args_test.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2021-08-10 19:42:33 +0200
committerJakob Unterwurzacher2021-08-10 19:42:33 +0200
commit0c16616117e9866cc49adc85738e3c9e3adf413a (patch)
tree5030b1bad61e22870ad724299e9d0b3c2827882b /cli_args_test.go
parent463f6e8962d87bf45dccd806822d40cfff335695 (diff)
main: add testcases for convertToDoubleDash & parseCliOpts
Diffstat (limited to 'cli_args_test.go')
-rw-r--r--cli_args_test.go104
1 files changed, 104 insertions, 0 deletions
diff --git a/cli_args_test.go b/cli_args_test.go
index 6dff1f1..97f9473 100644
--- a/cli_args_test.go
+++ b/cli_args_test.go
@@ -3,6 +3,8 @@ package main
import (
"reflect"
"testing"
+
+ "github.com/rfjakob/gocryptfs/internal/stupidgcm"
)
// TestPrefixOArgs checks that the "-o x,y,z" parsing works correctly.
@@ -75,3 +77,105 @@ func TestPrefixOArgs(t *testing.T) {
}
}
}
+
+func TestConvertToDoubleDash(t *testing.T) {
+ testcases := []struct {
+ // i is the input
+ i []string
+ // o is the expected output
+ o []string
+ }{
+ {
+ i: nil,
+ o: nil,
+ },
+ {
+ i: []string{"gocryptfs"},
+ o: []string{"gocryptfs"},
+ },
+ {
+ i: []string{"gocryptfs", "foo"},
+ o: []string{"gocryptfs", "foo"},
+ },
+ {
+ i: []string{"gocryptfs", "-v", "-quiet"},
+ o: []string{"gocryptfs", "--v", "--quiet"},
+ },
+ {
+ i: []string{"gocryptfs", "--", "-foo"},
+ o: []string{"gocryptfs", "--", "-foo"},
+ },
+ }
+ for _, tc := range testcases {
+ o := convertToDoubleDash(tc.i)
+ if !reflect.DeepEqual(o, tc.o) {
+ t.Errorf("in=%q\nwant=%q\nhave=%q", tc.i, tc.o, o)
+ }
+ }
+}
+
+func TestParseCliOpts(t *testing.T) {
+ defaultArgs := argContainer{
+ longnames: true,
+ raw64: true,
+ hkdf: true,
+ openssl: stupidgcm.PreferOpenSSL(), // depends on CPU and build flags
+ scryptn: 16,
+ }
+
+ type testcaseContainer struct {
+ // i is the input
+ i []string
+ // o is the expected output
+ o argContainer
+ }
+
+ var testcases []testcaseContainer
+
+ testcases = append(testcases, testcaseContainer{
+ i: []string{"gocryptfs"},
+ o: defaultArgs,
+ })
+
+ o := defaultArgs
+ o.quiet = true
+ testcases = append(testcases, testcaseContainer{
+ i: []string{"gocryptfs", "-q"},
+ o: o,
+ })
+ testcases = append(testcases, testcaseContainer{
+ i: []string{"gocryptfs", "--q"},
+ o: o,
+ })
+ testcases = append(testcases, testcaseContainer{
+ i: []string{"gocryptfs", "-quiet"},
+ o: o,
+ })
+ testcases = append(testcases, testcaseContainer{
+ i: []string{"gocryptfs", "--quiet"},
+ o: o,
+ })
+
+ o = defaultArgs
+ o.exclude = []string{"foo", "bar"}
+ testcases = append(testcases, testcaseContainer{
+ i: []string{"gocryptfs", "-e", "foo", "-e", "bar"},
+ o: o,
+ })
+ testcases = append(testcases, testcaseContainer{
+ i: []string{"gocryptfs", "--exclude", "foo", "--exclude", "bar"},
+ o: o,
+ })
+ /* TODO BROKEN
+ testcases = append(testcases, testcaseContainer{
+ i: []string{"gocryptfs", "--exclude", "foo", "-e", "bar"},
+ o: o,
+ })
+ */
+ for _, tc := range testcases {
+ o := parseCliOpts(tc.i)
+ if !reflect.DeepEqual(o, tc.o) {
+ t.Errorf("in=%v\nwant=%v\nhave=%v", tc.i, tc.o, o)
+ }
+ }
+}