-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathrouter_test.go
93 lines (79 loc) · 1.73 KB
/
router_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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package main
import (
. "github.com/smartystreets/goconvey/convey"
"testing"
)
func TestBuildRegexpFromGlobPattern_0(t *testing.T) {
a, err := BuildRegexpFromGlobPattern("a.b.c")
if err != nil {
t.Fail()
}
if a != "^a\\.b\\.c$" {
t.Fail()
}
}
func TestBuildRegexpFromGlobPattern_1(t *testing.T) {
a, err := BuildRegexpFromGlobPattern("a.*.c")
if err != nil {
t.Fail()
}
if a != "^a\\.[^.]*\\.c$" {
t.Fail()
}
}
func TestBuildRegexpFromGlobPattern_2(t *testing.T) {
a, err := BuildRegexpFromGlobPattern("**c")
if err != nil {
t.Fail()
}
if a != "^.*c$" {
t.Fail()
}
}
func TestBuildRegexpFromGlobPattern_3(t *testing.T) {
a, err := BuildRegexpFromGlobPattern("**.c")
if err != nil {
t.Fail()
}
if a != "^(?:.*\\.|^)c$" {
t.Fail()
}
}
func TestBuildRegexpFromGlobPattern_4(t *testing.T) {
a, err := BuildRegexpFromGlobPattern("a.{b,c}.d")
if err != nil {
t.Fail()
}
if a != "^a\\.(?:(?:b)|(?:c))\\.d$" {
t.Fail()
}
}
func TestRouter(t *testing.T) {
in := make(chan *PipelinePack)
out := make(chan *PipelinePack, 1)
router := new(Router)
router.Init()
router.AddInChan(in)
router.AddOutChan("test.**", out)
go router.Loop()
one := NewPipelinePack(in)
one.Msg.Tag = "test.one"
in <- one
Convey("Confirm the outputs from outchan", t, func() {
// Get the one pipelinepack and confirm it
So(len(out), ShouldEqual, 1)
res := <-out
So(res.Msg.Tag, ShouldEqual, "test.one")
// We should get the three pipelinepack,
// instead of blocking the main loop of router
two := NewPipelinePack(in)
two.Msg.Tag = "test.two"
in <- two
three := NewPipelinePack(in)
three.Msg.Tag = "test.three"
in <- three
So(len(out), ShouldEqual, 1)
res = <-out
So(res.Msg.Tag, ShouldEqual, "test.three")
})
}