-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode_test.go
50 lines (39 loc) · 1.02 KB
/
node_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
package plugo
import (
"testing"
)
func TestNodeTree(t *testing.T) {
tree := newNode("/")
users := tree.insertNode("users")
t.Run("check sub nodes", func(t *testing.T) {
if tree.kind != nodeStatic {
t.Error("node kind parsing error")
}
if users.kind != nodeStatic {
t.Error("node kind parsing error")
}
if len(tree.children) != 1 || len(tree.statics) != 1 {
t.Error("error inserting a new sub node")
}
})
tree.bind(MethodGet, "/", NewPlug(nil))
users.bind(MethodPost, "/users", NewPlug(nil))
t.Run("check endpoints", func(t *testing.T) {
var endp *endpoint
endp = tree.endpoints.Value(MethodGet)
if endp == nil {
t.Error("error binding method")
}
endp = users.endpoints.Value(MethodPost)
if endp == nil {
t.Error("error binding method")
}
})
avy := users.insertNode("avatar")
avy.insertNode(":id")
t.Run("check node params", func(t *testing.T) {
if avy.params == nil {
t.Error("error inserting parametric node")
}
})
}