package mooh import ( "net/http" "net/url" "testing" "regexp" ) func testRequestRoute(req *Request) (Response, error) { resp := Response{} return resp, nil } func buildDispatcher() Dispatcher { router := BuildDispatcher() router.AddRoute(&Route{ Method: "GET", Path: "/foo/:bar", Code: testRequestRoute, Validations: map[string]*regexp.Regexp{ "bar": regexp.MustCompile("\\w+"), }, }) return router } func TestBasicRequest(t *testing.T) { router := buildDispatcher() t.Log(router.routes[0].components) r := &http.Request{Method: "GET", URL: &url.URL{Path: "/foo/bar"}} m, _ := router.Match(r) request := NewRequest(r, m) if request == nil { t.Fatal() } if p := request.RouteParam("bar"); p != "bar" { t.Fatal() } }