-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathexchange_test.go
45 lines (40 loc) · 1.02 KB
/
exchange_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
package main
import (
"testing"
"time"
"github.com/eternal-flame-AD/gotify-broadcast/model"
plugin "github.com/gotify/plugin-api"
. "github.com/smartystreets/goconvey/convey"
)
func TestMessageExchange(t *testing.T) {
Convey("Test Message Exchange", t, func(c C) {
exchanger := newMessageExchange()
c.Convey("sends messages", func(c C) {
exchanger.MsgChan <- model.Message{}
})
c.Convey("callback receives mesasges", func(c C) {
test1Received, test2Received := make(chan struct{}), make(chan struct{})
exchanger.OnMessage(func(msg model.Message) {
if msg.Sender.ID == 1 {
close(test1Received)
}
})
exchanger.OnMessage(func(msg model.Message) {
if msg.Sender.ID == 1 {
close(test2Received)
}
})
exchanger.MsgChan <- model.Message{Sender: plugin.UserContext{ID: 1}}
select {
case <-test1Received:
case <-time.After(1 * time.Second):
t.Error("timeout")
}
select {
case <-test2Received:
case <-time.After(1 * time.Second):
t.Error("timeout")
}
})
})
}