-
Notifications
You must be signed in to change notification settings - Fork 32
/
conn_test.go
65 lines (51 loc) · 1.54 KB
/
conn_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
package wireless
import (
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestProcessMessage(t *testing.T) {
c := &Conn{}
Convey("given an event message", t, func() {
data := []byte("<3>" + EventConnected + " ssid=watership")
n := len(data)
Convey("and a subscription to that event", func() {
sub := c.Subscribe(EventConnected)
Convey("when the message is processed", func() {
c.processMessage(n, data, nil)
Convey("then the event should be published", func() {
So(sub.ch, ShouldHaveLength, 1)
ev := <-sub.Next()
So(ev.Name, ShouldEqual, EventConnected)
})
})
})
})
Convey("given a log message", t, func() {
data := []byte("<3>hey hey hey")
n := len(data)
Convey("and a subscription to that logs", func() {
sub := c.Subscribe("logs")
Convey("when the message is processed", func() {
c.processMessage(n, data, nil)
Convey("then the event should be published", func() {
So(sub.ch, ShouldHaveLength, 1)
ev := <-sub.Next()
So(ev.Name, ShouldEqual, "logs")
So(ev.Arguments["msg"], ShouldEqual, "hey hey hey")
})
})
})
})
Convey("given a command response", t, func() {
data := []byte("OK\n")
n := len(data)
c.currentCommandResponse = make(chan string, 1)
Convey("when the message is processed", func() {
c.processMessage(n, data, nil)
Convey("then it should be put in the command response channel", func() {
So(c.currentCommandResponse, ShouldHaveLength, 1)
So(<-c.currentCommandResponse, ShouldEqual, "OK\n")
})
})
})
}