forked from djui/await
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
75 lines (68 loc) · 1.6 KB
/
main_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
package main
import (
"flag"
"os"
"testing"
)
func TestSplitArgsResourceAndCommand(t *testing.T) {
os.Args = []string{"./await", "true", "--", "echo"}
flag.Parse()
res, cmd := splitArgs(flag.Args())
if len(res) != 1 || res[0] != "true" {
t.Errorf("no resources found")
}
if len(cmd) != 1 || cmd[0] != "echo" {
t.Errorf("no command found")
}
}
func TestSplitArgsResourceAndNoCommand(t *testing.T) {
os.Args = []string{"./await", "true", "--"}
flag.Parse()
res, cmd := splitArgs(flag.Args())
if len(res) != 1 || res[0] != "true" {
t.Errorf("no resources found")
}
if len(cmd) != 0 {
t.Errorf("unexpected command found")
}
os.Args = []string{"./await", "true"}
flag.Parse()
res, cmd = splitArgs(flag.Args())
if len(res) != 1 || res[0] != "true" {
t.Errorf("no resources found")
}
if len(cmd) != 0 {
t.Errorf("unexpected command found")
}
}
func TestSplitArgsNoResourceAndCommand(t *testing.T) {
os.Args = []string{"./await", "--", "echo"}
flag.Parse()
res, cmd := splitArgs(flag.Args())
if len(res) != 0 {
t.Errorf("unexpected resource found")
}
if len(cmd) != 1 || cmd[0] != "echo" {
t.Errorf("no command found")
}
}
func TestSplitArgsNoResourceNoCommand(t *testing.T) {
os.Args = []string{"./await", "--"}
flag.Parse()
res, cmd := splitArgs(flag.Args())
if len(res) != 0 {
t.Errorf("unexpected resource found")
}
if len(cmd) != 0 {
t.Errorf("unexpected command found")
}
os.Args = []string{"./await"}
flag.Parse()
res, cmd = splitArgs(flag.Args())
if len(res) != 0 {
t.Errorf("unexpected resource found")
}
if len(cmd) != 0 {
t.Errorf("unexpected command found")
}
}