-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy patharguments_test.go
85 lines (80 loc) · 2.3 KB
/
arguments_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
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
80
81
82
83
84
85
package main
import (
"regexp"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestGetArguments(t *testing.T) {
for _, c := range []struct {
argv []string
args arguments
}{
{
argv: []string{"file"},
args: arguments{[]string{"file"}, "", defaultConcurrency, 0, nil, false, false},
},
{
argv: []string{"-c", "42", "file"},
args: arguments{[]string{"file"}, "", 42, 0, nil, false, false},
},
{
argv: []string{"--concurrency", "42", "file"},
args: arguments{[]string{"file"}, "", 42, 0, nil, false, false},
},
{
argv: []string{"-d", "directory", "file"},
args: arguments{[]string{"file"}, "directory", defaultConcurrency, 0, nil, false, false},
},
{
argv: []string{"--document-root", "directory", "file"},
args: arguments{[]string{"file"}, "directory", defaultConcurrency, 0, nil, false, false},
},
{
argv: []string{"-r", "file"},
args: arguments{[]string{"file"}, "", defaultConcurrency, 0, nil, true, false},
},
{
argv: []string{"--recursive", "file"},
args: arguments{[]string{"file"}, "", defaultConcurrency, 0, nil, true, false},
},
{
argv: []string{"-t", "42", "file"},
args: arguments{[]string{"file"}, "", defaultConcurrency, 42 * time.Second, nil, false, false},
},
{
argv: []string{"--timeout", "42", "file"},
args: arguments{[]string{"file"}, "", defaultConcurrency, 42 * time.Second, nil, false, false},
},
{
argv: []string{"-x", "^.*$", "file"},
args: arguments{[]string{"file"}, "", defaultConcurrency, 0, regexp.MustCompile(`^.*$`), false, false},
},
{
argv: []string{"--exclude", "^.*$", "file"},
args: arguments{[]string{"file"}, "", defaultConcurrency, 0, regexp.MustCompile(`^.*$`), false, false},
},
{
argv: []string{"-v", "file"},
args: arguments{[]string{"file"}, "", defaultConcurrency, 0, nil, false, true},
},
{
argv: []string{"--verbose", "file"},
args: arguments{[]string{"file"}, "", defaultConcurrency, 0, nil, false, true},
},
} {
args, err := getArguments(c.argv)
assert.Equal(t, nil, err)
assert.Equal(t, args, c.args)
}
}
func TestGetArgumentsWithInvalidArgv(t *testing.T) {
for _, argv := range [][]string{
{"-c", "3.14", "file"},
{"-t", "foo", "file"},
{"-c", "-t", "file"},
} {
_, err := getArguments(argv)
assert.NotEqual(t, nil, err)
}
}