summaryrefslogtreecommitdiff
path: root/cli_args_test.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2018-06-05 21:02:35 +0200
committerJakob Unterwurzacher2018-06-05 21:02:35 +0200
commite29a81efc3df88b451a4a9464724a952d97b4115 (patch)
tree04efcc8e5cb0101ec12b9a6e3238a874675b97cc /cli_args_test.go
parent98aa9cb1768985b5f4dff33eebf1bc0ebd4a90b3 (diff)
main: make prefixOArgs errors testable
By returning an error instead of calling os.Exit, error cases can be tested easily. Error cases were not tested until now.
Diffstat (limited to 'cli_args_test.go')
-rw-r--r--cli_args_test.go14
1 files changed, 11 insertions, 3 deletions
diff --git a/cli_args_test.go b/cli_args_test.go
index 63a33ef..dd5dcd1 100644
--- a/cli_args_test.go
+++ b/cli_args_test.go
@@ -10,6 +10,8 @@ type testcase struct {
i []string
// o is the expected output
o []string
+ // Do we expect an error?
+ e bool
}
// TestPrefixOArgs checks that the "-o x,y,z" parsing works correctly.
@@ -61,11 +63,17 @@ func TestPrefixOArgs(t *testing.T) {
i: []string{"gocryptfs", "--", "-o", "a"},
o: []string{"gocryptfs", "--", "-o", "a"},
},
+ // This should error out
+ {
+ i: []string{"gocryptfs", "foo", "bar", "-o"},
+ e: true,
+ },
}
for _, tc := range testcases {
- o := prefixOArgs(tc.i)
- if !reflect.DeepEqual(o, tc.o) {
- t.Errorf("\n in=%q\nwant=%q\n got=%q", tc.i, tc.o, o)
+ o, err := prefixOArgs(tc.i)
+ e := (err != nil)
+ if !reflect.DeepEqual(o, tc.o) || e != tc.e {
+ t.Errorf("\n in=%q\nwant=%q err=%v\n got=%q err=%v", tc.i, tc.o, tc.e, o, e)
}
}
}