MCPcopy
hub / github.com/julienschmidt/httprouter / TestTreeDupliatePath

Function TestTreeDupliatePath

tree_test.go:273–309  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

271}
272
273func TestTreeDupliatePath(t *testing.T) {
274 tree := &node{}
275
276 routes := [...]string{
277 "/",
278 "/doc/",
279 "/src/*filepath",
280 "/search/:query",
281 "/user_:name",
282 }
283 for _, route := range routes {
284 recv := catchPanic(func() {
285 tree.addRoute(route, fakeHandler(route))
286 })
287 if recv != nil {
288 t.Fatalf("panic inserting route '%s': %v", route, recv)
289 }
290
291 // Add again
292 recv = catchPanic(func() {
293 tree.addRoute(route, nil)
294 })
295 if recv == nil {
296 t.Fatalf("no panic while inserting duplicate route '%s", route)
297 }
298 }
299
300 //printChildren(tree, "")
301
302 checkRequests(t, tree, testRequests{
303 {"/", false, "/", nil},
304 {"/doc/", false, "/doc/", nil},
305 {"/src/some/file.png", false, "/src/*filepath", Params{Param{"filepath", "/some/file.png"}}},
306 {"/search/someth!ng+in+ünìcodé", false, "/search/:query", Params{Param{"query", "someth!ng+in+ünìcodé"}}},
307 {"/user_gopher", false, "/user_:name", Params{Param{"name", "gopher"}}},
308 })
309}
310
311func TestEmptyWildcardName(t *testing.T) {
312 tree := &node{}

Callers

nothing calls this directly

Calls 4

addRouteMethod · 0.95
catchPanicFunction · 0.85
fakeHandlerFunction · 0.85
checkRequestsFunction · 0.85

Tested by

no test coverage detected