2016-10-09 20:54:40 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
type testcase struct {
|
|
|
|
// i is the input
|
|
|
|
i []string
|
|
|
|
// o is the expected output
|
|
|
|
o []string
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPrefixOArgs(t *testing.T) {
|
|
|
|
testcases := []testcase{
|
2016-10-24 19:36:44 +02:00
|
|
|
{
|
2016-10-09 20:54:40 +02:00
|
|
|
i: nil,
|
|
|
|
o: nil,
|
|
|
|
},
|
2016-10-24 19:36:44 +02:00
|
|
|
{
|
2016-10-09 20:54:40 +02:00
|
|
|
i: []string{"gocryptfs"},
|
|
|
|
o: []string{"gocryptfs"},
|
|
|
|
},
|
2016-10-24 19:36:44 +02:00
|
|
|
{
|
2016-10-09 20:54:40 +02:00
|
|
|
i: []string{"gocryptfs", "-v"},
|
|
|
|
o: []string{"gocryptfs", "-v"},
|
|
|
|
},
|
2016-10-24 19:36:44 +02:00
|
|
|
{
|
2016-10-09 20:54:40 +02:00
|
|
|
i: []string{"gocryptfs", "foo", "bar", "-v"},
|
|
|
|
o: []string{"gocryptfs", "foo", "bar", "-v"},
|
|
|
|
},
|
2016-10-24 19:36:44 +02:00
|
|
|
{
|
2016-10-09 20:54:40 +02:00
|
|
|
i: []string{"gocryptfs", "foo", "bar", "-o", "a"},
|
|
|
|
o: []string{"gocryptfs", "-a", "foo", "bar"},
|
|
|
|
},
|
2016-10-24 19:36:44 +02:00
|
|
|
{
|
2016-10-09 20:54:40 +02:00
|
|
|
i: []string{"gocryptfs", "foo", "bar", "-o", "a,b,xxxxx"},
|
|
|
|
o: []string{"gocryptfs", "-a", "-b", "-xxxxx", "foo", "bar"},
|
|
|
|
},
|
2016-10-24 19:36:44 +02:00
|
|
|
{
|
2016-10-10 19:44:34 +02:00
|
|
|
i: []string{"gocryptfs", "foo", "bar", "-d", "-o=a,b,xxxxx"},
|
|
|
|
o: []string{"gocryptfs", "-a", "-b", "-xxxxx", "foo", "bar", "-d"},
|
|
|
|
},
|
2016-10-24 19:36:44 +02:00
|
|
|
{
|
2016-10-09 20:54:40 +02:00
|
|
|
i: []string{"gocryptfs", "foo", "bar", "-oooo", "a,b,xxxxx"},
|
|
|
|
o: []string{"gocryptfs", "foo", "bar", "-oooo", "a,b,xxxxx"},
|
|
|
|
},
|
2016-10-10 19:44:34 +02:00
|
|
|
// https://github.com/mhogomchungu/sirikali/blob/a36d91d3e39f0c1eb9a79680ed6c28ddb6568fa8/src/siritask.cpp#L192
|
2016-10-24 19:36:44 +02:00
|
|
|
{
|
2016-10-10 19:44:34 +02:00
|
|
|
i: []string{"gocryptfs", "-o", "rw", "--config", "fff", "ccc", "mmm"},
|
|
|
|
o: []string{"gocryptfs", "-rw", "--config", "fff", "ccc", "mmm"},
|
|
|
|
},
|
2016-10-09 20:54:40 +02:00
|
|
|
}
|
|
|
|
for _, tc := range testcases {
|
|
|
|
o := prefixOArgs(tc.i)
|
|
|
|
if !reflect.DeepEqual(o, tc.o) {
|
2016-10-10 19:44:34 +02:00
|
|
|
t.Errorf("\n in=%q\nwant=%q\n got=%q", tc.i, tc.o, o)
|
2016-10-09 20:54:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|