-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathcli_test.go
74 lines (62 loc) · 1.09 KB
/
cli_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
package config
import (
"testing"
"github.com/urfave/cli"
)
func TestCLILoad(t *testing.T) {
var executed bool
app := cli.NewApp()
app.Flags = []cli.Flag{
&cli.IntFlag{
Name: "timeout",
},
&cli.Float64Flag{
Name: "frequency",
},
&cli.StringFlag{
Name: "time_zone",
},
&cli.BoolFlag{
Name: "enabled",
},
}
app.Action = func(c *cli.Context) error {
executed = true
cliProvider := NewCLI(c, false)
expectedSettings := map[string]string{
"timeout": "30",
"frequency": "0.5",
"time_zone": "PST",
"enabled": "true",
}
actualSettings, err := cliProvider.Load()
if err != nil {
t.Fatal(err)
}
for key, expected := range expectedSettings {
actual, ok := actualSettings[key]
if !ok {
t.Errorf("Key '%s' not in settings", key)
}
if actual != expected {
t.Errorf("Setting '%s' was '%s', expected '%s'", key, actual, expected)
}
}
return err
}
app.Run(
[]string{
"main.go",
"--timeout",
"30",
"--frequency",
"0.5",
"--time_zone",
"PST",
"--enabled",
},
)
if !executed {
t.Fail()
}
}