-
Notifications
You must be signed in to change notification settings - Fork 0
/
router_test.go
45 lines (40 loc) · 1.08 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
package ela
import (
"github.com/gogather/com/log"
. "github.com/smartystreets/goconvey/convey"
"testing"
)
func TestRouter(t *testing.T) {
log.Debug = true
Convey("Router sections", t, func() {
e := Web()
e.Router("/:hello/:world/123", 123, 456)
e.Router("/:hello/123", 1234)
e.Router("/", "index")
node1 := getController("/param1/param2/123").(uriMode)
ctrl1 := node1.fun
param1 := node1.argsMap
node2 := getController("/param1/123").(uriMode)
ctrl2 := node2.fun
param2 := node2.argsMap
node3 := getController("/").(uriMode)
ctrl3 := node3.fun
param3 := node3.argsMap
log.Greenln(ctrl1)
log.Greenln(param1)
log.Greenln(ctrl2)
log.Greenln(param2)
log.Greenln(ctrl3)
log.Greenln(param3)
getArgs("/param1/param2/123", "/:hello/:world/123")
uri := parseURI("/test?hello=world")
log.Greenln(uri)
So(ctrl1, ShouldContain, 123)
So(ctrl1, ShouldContain, 456)
So(ctrl2, ShouldContain, 1234)
So(ctrl3, ShouldContain, "index")
So(param1["hello"], ShouldEqual, "param1")
So(param1["world"], ShouldEqual, "param2")
So(uri, ShouldEqual, "/test")
})
}