about summary refs log tree commit diff
path: root/router_test.go
diff options
context:
space:
mode:
authorFranck Cuny <franck@lumberjaph.net>2013-04-28 14:50:46 -0700
committerFranck Cuny <franck@lumberjaph.net>2013-04-28 14:50:46 -0700
commit8eae5e3b8c61eb2ed31c86ae672c2395b0ed02a0 (patch)
tree0166b859443654dfa5448e4047c57ca6267aad1a /router_test.go
parentAdd a few more methods for future introspection to the Router. (diff)
downloadpath-router-8eae5e3b8c61eb2ed31c86ae672c2395b0ed02a0.tar.gz
Add a method to get the HTTP methods supported for a path.
Diffstat (limited to '')
-rw-r--r--router_test.go29
1 files changed, 26 insertions, 3 deletions
diff --git a/router_test.go b/router_test.go
index 3b94699..de13225 100644
--- a/router_test.go
+++ b/router_test.go
@@ -4,18 +4,18 @@ import (
 	"testing"
 )
 
-func testRouter (req *Request) (Response, error) {
+func testRouter(req *Request) (Response, error) {
 	resp := Response{}
 	return resp, nil
 }
 
 func testBasic(t *testing.T) {
 	d := BuildRouter()
-	err := d.AddRoute(&Route{Method:"GET", Path:"/", Code: testRouter})
+	err := d.AddRoute(&Route{Method: "GET", Path: "/", Code: testRouter})
 	if err != nil {
 		t.Fatal()
 	}
-	err = d.AddRoute(&Route{Method: "GET", Path:"/", Code: testRouter})
+	err = d.AddRoute(&Route{Method: "GET", Path: "/", Code: testRouter})
 	if err == nil {
 		t.Fatal()
 	}
@@ -100,3 +100,26 @@ func TestGetAllRoutesByMethod(t *testing.T) {
 		t.Fatal()
 	}
 }
+
+func TestGetMethodsForPath(t *testing.T) {
+	r := BuildRouter()
+	r.AddRoute(&Route{Method: "GET", Path: "/foo", Code: testRoute})
+	r.AddRoute(&Route{Method: "GET", Path: "/foo/bar", Code: testRoute})
+	r.AddRoute(&Route{Method: "PUT", Path: "/foo", Code: testRoute})
+	r.AddRoute(&Route{Method: "POST", Path: "/foo", Code: testRoute})
+
+	m := r.GetMethodsForPath("/foo")
+	if len(m) != 3 {
+		t.Fatal()
+	}
+
+	m = r.GetMethodsForPath("/foo/bar")
+	if len(m) != 1 {
+		t.Fatal()
+	}
+
+	m = r.GetMethodsForPath("/foo/bar/baz")
+	if len(m) != 0 {
+		t.Fatal()
+	}
+}