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

Function TestBuildVarsFunc

mux_test.go:1163–1199  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1161}
1162
1163func TestBuildVarsFunc(t *testing.T) {
1164 tests := []routeTest{
1165 {
1166 title: "BuildVarsFunc set on route",
1167 route: new(Route).Path(`/111/{v1:\d}{v2:.*}`).BuildVarsFunc(func(vars map[string]string) map[string]string {
1168 vars["v1"] = "3"
1169 vars["v2"] = "a"
1170 return vars
1171 }),
1172 request: newRequest("GET", "http://localhost/111/2"),
1173 path: "/111/3a",
1174 pathTemplate: `/111/{v1:\d}{v2:.*}`,
1175 shouldMatch: true,
1176 },
1177 {
1178 title: "BuildVarsFunc set on route and parent route",
1179 route: new(Route).PathPrefix(`/{v1:\d}`).BuildVarsFunc(func(vars map[string]string) map[string]string {
1180 vars["v1"] = "2"
1181 return vars
1182 }).Subrouter().Path(`/{v2:\w}`).BuildVarsFunc(func(vars map[string]string) map[string]string {
1183 vars["v2"] = "b"
1184 return vars
1185 }),
1186 request: newRequest("GET", "http://localhost/1/a"),
1187 path: "/2/b",
1188 pathTemplate: `/{v1:\d}/{v2:\w}`,
1189 shouldMatch: true,
1190 },
1191 }
1192
1193 for _, test := range tests {
1194 t.Run(test.title, func(t *testing.T) {
1195 testRoute(t, test)
1196 testTemplate(t, test)
1197 })
1198 }
1199}
1200
1201func TestSubRouter(t *testing.T) {
1202 subrouter1 := new(Route).Host("{v1:[a-z]+}.google.com").Subrouter()

Callers

nothing calls this directly

Calls 7

newRequestFunction · 0.85
testRouteFunction · 0.85
testTemplateFunction · 0.85
SubrouterMethod · 0.80
BuildVarsFuncMethod · 0.45
PathMethod · 0.45
PathPrefixMethod · 0.45

Tested by

no test coverage detected