forked from wdvxdr1123/ZeroBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shell_test.go
45 lines (41 loc) · 993 Bytes
/
shell_test.go
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
package zero
import (
"reflect"
"strconv"
"testing"
"github.com/stretchr/testify/assert"
)
func Test_parse(t *testing.T) {
shellTests := [...]struct {
shell string
expected []string
}{
{`rm -rf /*`, []string{"rm", "-rf", "/*"}},
{`echo "cat cat" -n`, []string{"echo", "cat cat", "-n"}},
{`shutdown halt init`, []string{"shutdown", "halt", "init"}},
{`test test2`, []string{"test", "test2"}},
}
for i, v := range shellTests {
t.Run(strconv.Itoa(i), func(t *testing.T) {
out := ParseShell(v.shell)
assert.Equal(t, v.expected, out)
})
}
}
func Test_registerFlag(t *testing.T) {
type args struct {
RF bool `flag:"rf"`
File string `flag:"file"`
Count int `flag:"count"`
}
got := args{}
expected := args{
RF: true,
File: "123",
Count: 10,
}
fs := registerFlag(reflect.TypeOf(args{}), reflect.ValueOf(&got))
err := fs.Parse([]string{"-rf", "-file=123", "-count", "10"})
assert.NoError(t, err)
assert.Equal(t, expected, got)
}