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

Function TestTreeWildcardConflictEx

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

Source from the content-addressed store, hash-verified

940}
941
942func TestTreeWildcardConflictEx(t *testing.T) {
943 conflicts := [...]struct {
944 route string
945 segPath string
946 existPath string
947 existSegPath string
948 }{
949 {"/who/are/foo", "/foo", `/who/are/\*you`, `/\*you`},
950 {"/who/are/foo/", "/foo/", `/who/are/\*you`, `/\*you`},
951 {"/who/are/foo/bar", "/foo/bar", `/who/are/\*you`, `/\*you`},
952 {"/con:nection", ":nection", `/con:tact`, `:tact`},
953 }
954
955 for _, conflict := range conflicts {
956 // I have to re-create a 'tree', because the 'tree' will be
957 // in an inconsistent state when the loop recovers from the
958 // panic which threw by 'addRoute' function.
959 tree := &node{}
960 routes := [...]string{
961 "/con:tact",
962 "/who/are/*you",
963 "/who/foo/hello",
964 }
965
966 for _, route := range routes {
967 tree.addRoute(route, fakeHandler(route))
968 }
969
970 recv := catchPanic(func() {
971 tree.addRoute(conflict.route, fakeHandler(conflict.route))
972 })
973
974 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)) {
975 t.Fatalf("invalid wildcard conflict error (%v)", recv)
976 }
977 }
978}
979
980func TestTreeInvalidEscape(t *testing.T) {
981 routes := map[string]bool{

Callers

nothing calls this directly

Calls 3

addRouteMethod · 0.95
fakeHandlerFunction · 0.85
catchPanicFunction · 0.85

Tested by

no test coverage detected