-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrie_test.go
59 lines (48 loc) · 1.36 KB
/
trie_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
package art
import (
"testing"
)
func Test_trie_endpoint(t *testing.T) {
node := newTrie("/")
mw := ¶mHandler{middlewares: []Middleware{endpoint_mw()}}
node.addRoute("", 0, mw, []Middleware{})
defaultHandler := ¶mHandler{defaultHandler: endpoint_default}
node.addRoute("topic", 0, defaultHandler, []Middleware{})
handler1 := ¶mHandler{handler: endpoint1}
handler2 := ¶mHandler{handler: endpoint2}
node.addRoute("topic1/", 0, handler1, []Middleware{})
node.addRoute("topic2/users/", 0, handler2, []Middleware{})
node.addRoute("topic2/orders/", 0, handler2, []Middleware{})
node.addRoute("{topic}/game2/kindA/", 0, handler1, []Middleware{})
expectedSubjects := []string{
"topic.*",
"topic1/",
"topic2/orders/",
"topic2/users/",
"{topic}/game2/kindA/",
}
endpoints := node.endpoint()
for i, endpoint := range endpoints {
if endpoint[0] != expectedSubjects[i] {
t.Errorf("unexpected output: got %s, want %s", endpoint[0], expectedSubjects[i])
return
}
// t.Logf("subject=%v fn=%v\n", endpoint[0], endpoint[1])
}
}
func endpoint_default(_ *Message, _ any) error {
return nil
}
func endpoint1(_ *Message, _ any) error {
return nil
}
func endpoint2(_ *Message, _ any) error {
return nil
}
func endpoint_mw() Middleware {
return func(next HandleFunc) HandleFunc {
return func(_ *Message, _ any) error {
return nil
}
}
}