-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrabbit_test.go
More file actions
61 lines (57 loc) · 1.16 KB
/
rabbit_test.go
File metadata and controls
61 lines (57 loc) · 1.16 KB
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
package rabbit_cli
import (
"flag"
"fmt"
"testing"
"time"
)
func TestBase(t *testing.T) {
root := &Cmd{
Name: "root",
Description: "初始命令",
Run: func(c *Cmd, args []string) {
fmt.Println("args", args)
},
}
_, err := root.Execute([]string{"1"})
if err != nil {
fmt.Println(err)
}
_, err = root.Execute([]string{"root"})
if err != nil {
fmt.Println(err)
}
}
func TestGroupCmd(t *testing.T) {
g := &GroupCmd{
Description: "command group",
}
g.AddCmd(&Cmd{
Name: "help",
Description: "",
Run: func(c *Cmd, args []string) {
g.Usage()
},
})
_, err := g.ExecuteCmdLine("help")
if err != nil {
fmt.Println(err)
}
}
func TestFlagSetGet(t *testing.T) {
f := new(FlagSet)
f.FlagSet = flag.NewFlagSet("", flag.ContinueOnError)
f.String("a", "default", "")
f.Int("b", -1, "")
f.Uint("c", 0, "")
f.Float64("d", 0.0000009, "")
f.Bool("e", false, "")
f.Duration("f", time.Duration(time.Now().UnixNano()), "")
fmt.Println(f.GetString("a"))
fmt.Println(f.GetInt("b"))
fmt.Println(f.GetUint("c"))
fmt.Println(f.GetFloat64("d"))
fmt.Println(f.GetBool("e"))
fmt.Println(f.GetDuration("f"))
fmt.Println(f.GetDuration("g"))
}