-
Notifications
You must be signed in to change notification settings - Fork 180
/
router_test.go
90 lines (75 loc) · 1.51 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
package dotweb
import (
"testing"
"time"
"github.com/devfeel/dotweb/session"
"github.com/devfeel/dotweb/test"
)
func TestRouter_ServeHTTP(t *testing.T) {
param := &InitContextParam{
t,
"",
"",
test.ToDefault,
}
context := initAllContext(param)
app := New()
server := app.HttpServer
r := NewRouter(server)
r.ServeHTTP(context)
}
func TestWrapRouterHandle(t *testing.T) {
param := &InitContextParam{
t,
"",
"",
test.ToDefault,
}
context := initAllContext(param)
app := New()
server := app.HttpServer
router := server.Router().(*router)
// use default config
server.SetSessionConfig(session.NewDefaultRuntimeConfig())
handle := router.wrapRouterHandle(Index, false)
handle(context)
}
func TestLogWebsocketContext(t *testing.T) {
param := &InitContextParam{
t,
"",
"",
test.ToDefault,
}
context := initAllContext(param)
log := logWebsocketContext(context, time.Now().Unix())
t.Log("logContext:", log)
// test.NotNil(t,log)
test.Equal(t, "", "")
}
func BenchmarkRouter_MatchPath(b *testing.B) {
app := New()
server := app.HttpServer
r := NewRouter(server)
r.GET("/1", func(ctx Context) error {
ctx.WriteString("1")
return nil
})
r.GET("/2", func(ctx Context) error {
ctx.WriteString("2")
return nil
})
r.POST("/p1", func(ctx Context) error {
ctx.WriteString("1")
return nil
})
r.POST("/p2", func(ctx Context) error {
ctx.WriteString("2")
return nil
})
for i := 0; i < b.N; i++ {
if root := r.Nodes["GET"]; root != nil {
root.getNode("/1?q=1")
}
}
}