1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
package main
import (
"reflect"
"testing"
)
type testcase struct {
// i is the input
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.
func TestPrefixOArgs(t *testing.T) {
testcases := []testcase{
{
i: nil,
o: nil,
},
{
i: []string{"gocryptfs"},
o: []string{"gocryptfs"},
},
{
i: []string{"gocryptfs", "-v"},
o: []string{"gocryptfs", "-v"},
},
{
i: []string{"gocryptfs", "foo", "bar", "-v"},
o: []string{"gocryptfs", "foo", "bar", "-v"},
},
{
i: []string{"gocryptfs", "foo", "bar", "-o", "a"},
o: []string{"gocryptfs", "-a", "foo", "bar"},
},
{
i: []string{"gocryptfs", "foo", "bar", "-o", "a,b,xxxxx"},
o: []string{"gocryptfs", "-a", "-b", "-xxxxx", "foo", "bar"},
},
{
i: []string{"gocryptfs", "foo", "bar", "-d", "-o=a,b,xxxxx"},
o: []string{"gocryptfs", "-a", "-b", "-xxxxx", "foo", "bar", "-d"},
},
{
i: []string{"gocryptfs", "foo", "bar", "-oooo", "a,b,xxxxx"},
o: []string{"gocryptfs", "foo", "bar", "-oooo", "a,b,xxxxx"},
},
// https://github.com/mhogomchungu/sirikali/blob/a36d91d3e39f0c1eb9a79680ed6c28ddb6568fa8/src/siritask.cpp#L192
{
i: []string{"gocryptfs", "-o", "rw", "--config", "fff", "ccc", "mmm"},
o: []string{"gocryptfs", "-rw", "--config", "fff", "ccc", "mmm"},
},
// "--" should also block "-o" parsing.
{
i: []string{"gocryptfs", "foo", "bar", "--", "-o", "a"},
o: []string{"gocryptfs", "foo", "bar", "--", "-o", "a"},
},
{
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, 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)
}
}
}
|