@@ -1850,6 +1850,11 @@ func TestMuxFind(t *testing.T) {
1850
1850
w .Header ().Set ("X-Test" , "yes" )
1851
1851
w .Write ([]byte ("bye" ))
1852
1852
})
1853
+ r .Route ("/yo" , func (r Router ) {
1854
+ r .Get ("/sup" , func (w http.ResponseWriter , r * http.Request ) {
1855
+ w .Write ([]byte ("sup" ))
1856
+ })
1857
+ })
1853
1858
r .Route ("/articles" , func (r Router ) {
1854
1859
r .Get ("/{id}" , func (w http.ResponseWriter , r * http.Request ) {
1855
1860
id := URLParam (r , "id" )
@@ -1868,17 +1873,54 @@ func TestMuxFind(t *testing.T) {
1868
1873
w .Write ([]byte ("user:" + id ))
1869
1874
})
1870
1875
})
1876
+ r .Route ("/api" , func (r Router ) {
1877
+ r .Route ("/groups" , func (r Router ) {
1878
+ r .Route ("/v2" , func (r Router ) {
1879
+ r .Get ("/" , func (w http.ResponseWriter , r * http.Request ) {
1880
+ w .Write ([]byte ("groups" ))
1881
+ })
1882
+ r .Post ("/{id}" , func (w http.ResponseWriter , r * http.Request ) {
1883
+ w .Write ([]byte ("POST groups" ))
1884
+ })
1885
+ })
1886
+ })
1887
+ })
1871
1888
1872
1889
tctx := NewRouteContext ()
1873
1890
1874
1891
tctx .Reset ()
1875
- if r .Find (tctx , "GET" , "/users/1 " ) == "/users/{id} " {
1876
- t .Fatal ("expecting to find match for route:" , " GET" , "/users/1 " )
1892
+ if r .Find (tctx , "GET" , "" ) == "/" {
1893
+ t .Fatal ("expecting to find pattern / for route: GET" )
1877
1894
}
1878
1895
1879
1896
tctx .Reset ()
1880
- if r .Find (tctx , "HEAD" , "/articles/10" ) == "/articles/{id}" {
1881
- t .Fatal ("not expecting to find match for route:" , "HEAD" , "/articles/10" )
1897
+ if r .Find (tctx , "GET" , "/nope" ) != "" {
1898
+ t .Fatal ("not expecting to find pattern for route: GET /nope" )
1899
+ }
1900
+
1901
+ tctx .Reset ()
1902
+ if r .Find (tctx , "GET" , "/users/1" ) != "/users/{id}" {
1903
+ t .Fatal ("expecting to find pattern /users/{id} for route: GET /users/1" )
1904
+ }
1905
+
1906
+ tctx .Reset ()
1907
+ if r .Find (tctx , "HEAD" , "/articles/10" ) != "" {
1908
+ t .Fatal ("not expecting to find pattern for route: HEAD /articles/10" )
1909
+ }
1910
+
1911
+ tctx .Reset ()
1912
+ if r .Find (tctx , "GET" , "/yo/sup" ) != "/yo/sup" {
1913
+ t .Fatal ("expecting to find pattern /yo/sup for route: GET /yo/sup" )
1914
+ }
1915
+
1916
+ tctx .Reset ()
1917
+ if r .Find (tctx , "GET" , "/api/groups/v2/" ) != "/api/groups/v2/" {
1918
+ t .Fatal ("expecting to find pattern /api/groups/v2/ for route: GET /api/groups/v2/" )
1919
+ }
1920
+
1921
+ tctx .Reset ()
1922
+ if r .Find (tctx , "POST" , "/api/groups/v2/1" ) != "/api/groups/v2/{id}" {
1923
+ t .Fatal ("expecting to find pattern /api/groups/v2/{id} for route: POST /api/groups/v2/1" )
1882
1924
}
1883
1925
}
1884
1926
0 commit comments