diff options
author | Franck Cuny <franck@lumberjaph.net> | 2013-04-21 11:06:41 -0700 |
---|---|---|
committer | Franck Cuny <franck@lumberjaph.net> | 2013-04-21 11:06:41 -0700 |
commit | 0e8f4dd672949c8b4e55d197c9bce0cf35da3f23 (patch) | |
tree | 5c4ceacd41fd5e8fbed8412e66f842c749a53275 | |
parent | The test was inversed. (diff) | |
download | path-router-0e8f4dd672949c8b4e55d197c9bce0cf35da3f23.tar.gz |
Add very simple test to validate routes.
-rw-r--r-- | router_test.go | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/router_test.go b/router_test.go new file mode 100644 index 0000000..5b85aa8 --- /dev/null +++ b/router_test.go @@ -0,0 +1,46 @@ +package mooh + +import ( + "net/http" + "net/url" + "testing" +) + +func testRoute(req *Request) (Response, error) { + resp := Response{} + return resp, nil +} + +func TestBasic(t *testing.T) { + router := BuildDispatcher() + router.AddRoute("/blog/:year/:month/:day", "GET", testRoute) + router.AddRoute("/blog", "GET", testRoute) + + if router.Routes[0].Path != "/blog/:year/:month/:day" { + t.Fatal() + } + if router.Routes[1].Path != "/blog" { + t.Fatal() + } +} + +func TestMatch(t *testing.T) { + router := BuildDispatcher() + router.AddRoute("/blog/:year/:month/:day", "GET", testRoute) + router.AddRoute("/blog", "GET", testRoute) + + pathToTests := []url.URL{ + url.URL{Path: "blog"}, + url.URL{Path: "/blog"}, + url.URL{Path: "blog/2013/4/21"}, + url.URL{Path: "/blog/2013/21/4"}, + } + for _, p := range pathToTests { + r := http.Request{URL: &p, Method: "GET"} + req := Request{&r} + m := router.Match(req) + if m == nil { + t.Fatal() + } + } +} |