(t *testing.T)
| 1161 | } |
| 1162 | |
| 1163 | func 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 | |
| 1201 | func TestSubRouter(t *testing.T) { |
| 1202 | subrouter1 := new(Route).Host("{v1:[a-z]+}.google.com").Subrouter() |
nothing calls this directly
no test coverage detected