-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_test.go
54 lines (44 loc) · 1.07 KB
/
run_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
package ctrl
import (
"github.com/afajl/ctrl/tests"
"os"
"strings"
"testing"
)
func TestFuncRun(t *testing.T) {
var nr_hosts int
hosts := []string{"a", "b"}
var seen_hosts [2]string
cmd := func(ctrl Ctrl) error {
seen_hosts[nr_hosts] = ctrl.Host().Name
nr_hosts++
return nil
}
routes := NewRoutes()
routes.AddFunc("cmd", cmd, "help")
os.Args = []string{"ctrl", "-dontlog", "-c", tests.SimpleConfig,
"-H", strings.Join(hosts, ","), "cmd"}
Start(routes)
if nr_hosts != 2 {
t.Fatal("nr hosts seen are not 2", nr_hosts)
}
for i := 0; i < len(hosts); i++ {
if hosts[i] != seen_hosts[i] {
t.Error("did not see host", hosts[i])
}
}
}
/*type TestCmd bool*/
/*func (c *TestCmd) Run(ctrl Ctrl) {}*/
/*type cmdmethod struct {*/
/*}*/
/*func (c *cmdmethod) F(ctrl Ctrl) error {*/
/*return nil*/
/*}*/
/*func TestMethodRun(t *testing.T) {*/
/*hosts := []string{"a", "b"}*/
/*cmd := &cmdmethod{}*/
/*routes := NewRoutes()*/
/*routes.AddFunc("cmd", cmd.F, "help")*/
/*startWithArgs([]string{"-c", emptyConfig, "-H", strings.Join(hosts, ","), "cmd"}, routes)*/
/*}*/