-
Notifications
You must be signed in to change notification settings - Fork 135
/
Copy pathdispatcher_test.go
42 lines (36 loc) · 942 Bytes
/
dispatcher_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
package dispatcher
import (
"testing"
"time"
)
type lgr struct{}
func (l *lgr) Fatalf(string, ...interface{}) {}
func (l *lgr) Errorf(string, ...interface{}) {}
func (l *lgr) Warnf(string, ...interface{}) {}
func (l *lgr) Infof(string, ...interface{}) {}
func (l *lgr) Debugf(string, ...interface{}) {}
func TestNewDispatcher(t *testing.T) {
d := NewDispatcher(&lgr{})
if d.subscribers == nil {
t.Error("Dispatcher subscribers is nil")
}
if d.subscribersMux == nil {
t.Error("Dispatcher subscribersMux is nil")
}
}
func TestAddSubscriber(t *testing.T) {
d := NewDispatcher(&lgr{})
d.AddSubscriber()
if len(d.subscribers) != 1 {
t.Error("Dispatcher subscribers length is not 1")
}
}
func TestCloseSubscriber(t *testing.T) {
d := NewDispatcher(&lgr{})
_, closeCh := d.AddSubscriber()
close(closeCh)
time.Sleep(time.Millisecond)
if len(d.subscribers) != 0 {
t.Error("Dispatcher subscribers length is not 0")
}
}