MCPcopy
hub / github.com/gin-gonic/gin / TestTreeDuplicatePath

Function TestTreeDuplicatePath

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

Source from the content-addressed store, hash-verified

455}
456
457func TestTreeDuplicatePath(t *testing.T) {
458 tree := &node{}
459
460 routes := [...]string{
461 "/",
462 "/doc/",
463 "/src/*filepath",
464 "/search/:query",
465 "/user_:name",
466 }
467 for _, route := range routes {
468 recv := catchPanic(func() {
469 tree.addRoute(route, fakeHandler(route))
470 })
471 if recv != nil {
472 t.Fatalf("panic inserting route '%s': %v", route, recv)
473 }
474
475 // Add again
476 recv = catchPanic(func() {
477 tree.addRoute(route, nil)
478 })
479 if recv == nil {
480 t.Fatalf("no panic while inserting duplicate route '%s", route)
481 }
482 }
483
484 // printChildren(tree, "")
485
486 checkRequests(t, tree, testRequests{
487 {"/", false, "/", nil},
488 {"/doc/", false, "/doc/", nil},
489 {"/src/some/file.png", false, "/src/*filepath", Params{Param{"filepath", "/some/file.png"}}},
490 {"/search/someth!ng+in+ünìcodé", false, "/search/:query", Params{Param{"query", "someth!ng+in+ünìcodé"}}},
491 {"/user_gopher", false, "/user_:name", Params{Param{"name", "gopher"}}},
492 })
493}
494
495func TestEmptyWildcardName(t *testing.T) {
496 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