MCPcopy
hub / github.com/gorilla/mux / TestSubRouter

Function TestSubRouter

mux_test.go:1201–1432  ·  mux_test.go::TestSubRouter
(t *testing.T)

Source from the content-addressed store, hash-verified

1199}
1200
1201func TestSubRouter(t *testing.T) {
1202 subrouter1 := new(Route).Host("{v1:[a-z]+}.google.com").Subrouter()
1203 subrouter2 := new(Route).PathPrefix("/foo/{v1}").Subrouter()
1204 subrouter3 := new(Route).PathPrefix("/foo").Subrouter()
1205 subrouter4 := new(Route).PathPrefix("/foo/bar").Subrouter()
1206 subrouter5 := new(Route).PathPrefix("/{category}").Subrouter()
1207 tests := []routeTest{
1208 {
1209 route: subrouter1.Path("/{v2:[a-z]+}"),
1210 request: newRequest("GET", "http://aaa.google.com/bbb"),
1211 vars: map[string]string{"v1": "aaa", "v2": "bbb"},
1212 host: "aaa.google.com",
1213 path: "/bbb",
1214 pathTemplate: `/{v2:[a-z]+}`,
1215 hostTemplate: `{v1:[a-z]+}.google.com`,
1216 shouldMatch: true,
1217 },
1218 {
1219 route: subrouter1.Path("/{v2:[a-z]+}"),
1220 request: newRequest("GET", "http://111.google.com/111"),
1221 vars: map[string]string{"v1": "aaa", "v2": "bbb"},
1222 host: "aaa.google.com",
1223 path: "/bbb",
1224 pathTemplate: `/{v2:[a-z]+}`,
1225 hostTemplate: `{v1:[a-z]+}.google.com`,
1226 shouldMatch: false,
1227 },
1228 {
1229 route: subrouter2.Path("/baz/{v2}"),
1230 request: newRequest("GET", "http://localhost/foo/bar/baz/ding"),
1231 vars: map[string]string{"v1": "bar", "v2": "ding"},
1232 host: "",
1233 path: "/foo/bar/baz/ding",
1234 pathTemplate: `/foo/{v1}/baz/{v2}`,
1235 shouldMatch: true,
1236 },
1237 {
1238 route: subrouter2.Path("/baz/{v2}"),
1239 request: newRequest("GET", "http://localhost/foo/bar"),
1240 vars: map[string]string{"v1": "bar", "v2": "ding"},
1241 host: "",
1242 path: "/foo/bar/baz/ding",
1243 pathTemplate: `/foo/{v1}/baz/{v2}`,
1244 shouldMatch: false,
1245 },
1246 {
1247 route: subrouter3.Path("/"),
1248 request: newRequest("GET", "http://localhost/foo/"),
1249 vars: map[string]string{},
1250 host: "",
1251 path: "/foo/",
1252 pathTemplate: `/foo/`,
1253 shouldMatch: true,
1254 },
1255 {
1256 route: subrouter3.Path(""),
1257 request: newRequest("GET", "http://localhost/foo"),
1258 vars: map[string]string{},

Callers

nothing calls this directly

Calls 13

newRequestFunction · 0.85
newRequestWithHeadersFunction · 0.85
testRouteFunction · 0.85
testTemplateFunction · 0.85
testUseEscapedRouteFunction · 0.85
SubrouterMethod · 0.80
HostMethod · 0.45
PathPrefixMethod · 0.45
PathMethod · 0.45
MethodsMethod · 0.45
SchemesMethod · 0.45
HeadersMethod · 0.45

Tested by

no test coverage detected