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

Function TestTreeFindCaseInsensitivePathWildcardParamAndStaticChild

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

Source from the content-addressed store, hash-verified

1064}
1065
1066func TestTreeFindCaseInsensitivePathWildcardParamAndStaticChild(t *testing.T) {
1067 tree := &node{}
1068
1069 // Another variant: param route + static route under same prefix
1070 routes := [...]string{
1071 "/prefix/:id",
1072 "/prefix/xxx",
1073 }
1074
1075 for _, route := range routes {
1076 recv := catchPanic(func() {
1077 tree.addRoute(route, fakeHandler(route))
1078 })
1079 if recv != nil {
1080 t.Fatalf("panic inserting route '%s': %v", route, recv)
1081 }
1082 }
1083
1084 // Should NOT panic even for paths that don't match any route
1085 out, found := tree.findCaseInsensitivePath("/prefix/a/b/c", true)
1086 if found {
1087 t.Errorf("Expected no match for '/prefix/a/b/c', but got: %s", string(out))
1088 }
1089
1090 // Exact match should still work
1091 out, found = tree.findCaseInsensitivePath("/prefix/xxx", true)
1092 if !found {
1093 t.Error("Route '/prefix/xxx' not found")
1094 } else if string(out) != "/prefix/xxx" {
1095 t.Errorf("Wrong result for '/prefix/xxx': %s", string(out))
1096 }
1097
1098 // Case-insensitive match should work
1099 out, found = tree.findCaseInsensitivePath("/PREFIX/XXX", true)
1100 if !found {
1101 t.Error("Route '/PREFIX/XXX' not found via case-insensitive lookup")
1102 } else if string(out) != "/prefix/xxx" {
1103 t.Errorf("Wrong result for '/PREFIX/XXX': expected '/prefix/xxx', got: %s", string(out))
1104 }
1105
1106 // Param route should still match
1107 out, found = tree.findCaseInsensitivePath("/prefix/something", true)
1108 if !found {
1109 t.Error("Route '/prefix/something' not found via param match")
1110 } else if string(out) != "/prefix/something" {
1111 t.Errorf("Wrong result for '/prefix/something': %s", string(out))
1112 }
1113}

Callers

nothing calls this directly

Calls 5

addRouteMethod · 0.95
catchPanicFunction · 0.85
fakeHandlerFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected