-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
controller_test.go
57 lines (49 loc) · 1.13 KB
/
controller_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
package dcc
import (
"testing"
"time"
"github.com/hsanjuan/go-dcc/driver/dummy"
)
func TestNewController(t *testing.T) {
cfg, _ := LoadConfig("./test/config.json")
c := NewControllerWithConfig(&dummy.DCCDummy{}, cfg)
c.Stop()
}
func TestAddLoco(t *testing.T) {
c := NewController(&dummy.DCCDummy{})
c.AddLoco(&Locomotive{})
}
func TestRmLoco(t *testing.T) {
c := NewController(&dummy.DCCDummy{})
c.AddLoco(&Locomotive{Name: "abc"})
c.RmLoco(&Locomotive{Name: "abc"})
_, ok := c.GetLoco("abc")
if ok {
t.Error("loco should have been deleted")
}
}
func TestLocos(t *testing.T) {
c := NewController(&dummy.DCCDummy{})
c.AddLoco(&Locomotive{Name: "abc"})
l := c.Locos()
if len(l) != 1 || l[0].Name != "abc" {
t.Error("Locos() does not work")
}
}
func TestCommand(t *testing.T) {
d := &dummy.DCCDummy{}
c := NewController(d)
p := NewBroadcastIdlePacket(d)
c.Command(p)
c.Start()
time.Sleep(250 * time.Millisecond)
c.Stop()
}
func TestStart(t *testing.T) {
c := NewController(&dummy.DCCDummy{})
c.Start()
time.Sleep(1 * time.Second)
c.AddLoco(&Locomotive{Name: "abc", Address: 10})
time.Sleep(1 * time.Second)
c.Stop()
}