-
-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathparse_test.go
95 lines (82 loc) · 1.61 KB
/
parse_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
86
87
88
89
90
91
92
93
94
95
package pget
import (
"testing"
"github.com/stretchr/testify/assert"
)
const version = "test_version"
func TestParts_of_ready(t *testing.T) {
cases := []struct {
name string
args []string
wantProcs int
wantURLs int
}{
{
name: "one URL",
args: []string{
"pget",
"-p",
"2",
"http://example.com/filename.tar.gz",
"--trace",
"--output",
"filename.tar.gz",
},
wantProcs: 2,
wantURLs: 1,
},
{
name: "two URLs",
args: []string{
"pget",
"-p",
"2",
"http://example.com/filename.tar.gz",
"http://example2.com/filename.tar.gz",
"--trace",
"--output",
"filename.tar.gz",
},
wantProcs: 4,
wantURLs: 2,
},
}
for _, tc := range cases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
p := New()
if err := p.Ready(version, tc.args); err != nil {
t.Errorf("failed to parse command line args: %s", err)
}
assert.Equal(t, true, p.Trace, "failed to parse arguments of trace")
assert.Equal(t, tc.wantProcs, p.Procs, "failed to parse arguments of procs")
assert.Equal(t, "filename.tar.gz", p.Output, "failed to parse output")
assert.Len(t, p.URLs, tc.wantURLs)
})
}
}
func TestShowhelp(t *testing.T) {
args := []string{
"pget",
"-h",
}
p := New()
_, err := p.parseOptions(args, version)
assert.NotNil(t, err)
args = []string{
"pget",
"--help",
}
p = New()
_, err = p.parseOptions(args, version)
assert.NotNil(t, err)
}
func TestShowisupdate(t *testing.T) {
args := []string{
"pget",
"--check-update",
}
p := New()
_, err := p.parseOptions(args, version)
assert.NotNil(t, err)
}