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

Function TestTreeWildcardConflictEx

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

Source from the content-addressed store, hash-verified

669}
670
671func TestTreeWildcardConflictEx(t *testing.T) {
672 conflicts := [...]struct {
673 route string
674 segPath string
675 existPath string
676 existSegPath string
677 }{
678 {"/who/are/foo", "/foo", `/who/are/\*you`, `/\*you`},
679 {"/who/are/foo/", "/foo/", `/who/are/\*you`, `/\*you`},
680 {"/who/are/foo/bar", "/foo/bar", `/who/are/\*you`, `/\*you`},
681 {"/conxxx", "xxx", `/con:tact`, `:tact`},
682 {"/conooo/xxx", "ooo", `/con:tact`, `:tact`},
683 }
684
685 for _, conflict := range conflicts {
686 // I have to re-create a 'tree', because the 'tree' will be
687 // in an inconsistent state when the loop recovers from the
688 // panic which threw by 'addRoute' function.
689 tree := &node{}
690 routes := [...]string{
691 "/con:tact",
692 "/who/are/*you",
693 "/who/foo/hello",
694 }
695
696 for _, route := range routes {
697 tree.addRoute(route, fakeHandler(route))
698 }
699
700 recv := catchPanic(func() {
701 tree.addRoute(conflict.route, fakeHandler(conflict.route))
702 })
703
704 if !regexp.MustCompile(fmt.Sprintf("'%s' in new path .* conflicts with existing wildcard '%s' in existing prefix '%s'", conflict.segPath, conflict.existSegPath, conflict.existPath)).MatchString(fmt.Sprint(recv)) {
705 t.Fatalf("invalid wildcard conflict error (%v)", recv)
706 }
707 }
708}

Callers

nothing calls this directly

Calls 3

addRouteMethod · 0.95
fakeHandlerFunction · 0.85
catchPanicFunction · 0.85

Tested by

no test coverage detected