Skip to content

Commit b9ff34f

Browse files
committed
Adding some extra tests, to hit all the use cases
1 parent 293ebe1 commit b9ff34f

File tree

1 file changed

+53
-5
lines changed

1 file changed

+53
-5
lines changed

mux_test.go

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,8 @@ func TestSubRouter(t *testing.T) {
10181018
subrouter1 := new(Route).Host("{v1:[a-z]+}.google.com").Subrouter()
10191019
subrouter2 := new(Route).PathPrefix("/foo/{v1}").Subrouter()
10201020
subrouter3 := new(Route).PathPrefix("/foo").Subrouter()
1021+
subrouter4 := new(Route).PathPrefix("/foo/bar").Subrouter()
1022+
subrouter5 := new(Route).PathPrefix("/{category}").Subrouter()
10211023

10221024
tests := []routeTest{
10231025
{
@@ -1049,6 +1051,15 @@ func TestSubRouter(t *testing.T) {
10491051
pathTemplate: `/foo/{v1}/baz/{v2}`,
10501052
shouldMatch: true,
10511053
},
1054+
{
1055+
route: subrouter2.Path("/baz/{v2}"),
1056+
request: newRequest("GET", "http://localhost/foo/bar"),
1057+
vars: map[string]string{"v1": "bar", "v2": "ding"},
1058+
host: "",
1059+
path: "/foo/bar/baz/ding",
1060+
pathTemplate: `/foo/{v1}/baz/{v2}`,
1061+
shouldMatch: false,
1062+
},
10521063
{
10531064
route: subrouter3.Path("/"),
10541065
request: newRequest("GET", "http://localhost/foo/"),
@@ -1059,13 +1070,50 @@ func TestSubRouter(t *testing.T) {
10591070
shouldMatch: true,
10601071
},
10611072
{
1062-
route: subrouter2.Path("/baz/{v2}"),
1073+
route: subrouter3.Path(""),
1074+
request: newRequest("GET", "http://localhost/foo"),
1075+
vars: map[string]string{},
1076+
host: "",
1077+
path: "/foo",
1078+
pathTemplate: `/foo`,
1079+
shouldMatch: true,
1080+
},
1081+
1082+
{
1083+
route: subrouter4.Path("/"),
1084+
request: newRequest("GET", "http://localhost/foo/bar/"),
1085+
vars: map[string]string{},
1086+
host: "",
1087+
path: "/foo/bar/",
1088+
pathTemplate: `/foo/bar/`,
1089+
shouldMatch: true,
1090+
},
1091+
{
1092+
route: subrouter4.Path(""),
10631093
request: newRequest("GET", "http://localhost/foo/bar"),
1064-
vars: map[string]string{"v1": "bar", "v2": "ding"},
1094+
vars: map[string]string{},
10651095
host: "",
1066-
path: "/foo/bar/baz/ding",
1067-
pathTemplate: `/foo/{v1}/baz/{v2}`,
1068-
shouldMatch: false,
1096+
path: "/foo/bar",
1097+
pathTemplate: `/foo/bar`,
1098+
shouldMatch: true,
1099+
},
1100+
{
1101+
route: subrouter5.Path("/"),
1102+
request: newRequest("GET", "http://localhost/baz/"),
1103+
vars: map[string]string{"category": "baz"},
1104+
host: "",
1105+
path: "/baz/",
1106+
pathTemplate: `/{category}/`,
1107+
shouldMatch: true,
1108+
},
1109+
{
1110+
route: subrouter5.Path(""),
1111+
request: newRequest("GET", "http://localhost/baz"),
1112+
vars: map[string]string{"category": "baz"},
1113+
host: "",
1114+
path: "/baz",
1115+
pathTemplate: `/{category}`,
1116+
shouldMatch: true,
10691117
},
10701118
}
10711119

0 commit comments

Comments
 (0)