mirror of
https://github.com/gin-gonic/gin.git
synced 2025-12-13 13:12:17 +08:00
formatted
This commit is contained in:
parent
9b3d7f632a
commit
a9b0085e40
18
tree_test.go
18
tree_test.go
@ -521,16 +521,16 @@ func TestTreeChildConflict(t *testing.T) {
|
|||||||
func TestWildcardConflictWithStringsCut(t *testing.T) {
|
func TestWildcardConflictWithStringsCut(t *testing.T) {
|
||||||
// Test the strings.Cut usage in wildcard conflict detection (line 258 in tree.go)
|
// Test the strings.Cut usage in wildcard conflict detection (line 258 in tree.go)
|
||||||
tree := &node{}
|
tree := &node{}
|
||||||
|
|
||||||
// Add a route with a wildcard parameter
|
// Add a route with a wildcard parameter
|
||||||
tree.addRoute("/user/:name", fakeHandler("/user/:name"))
|
tree.addRoute("/user/:name", fakeHandler("/user/:name"))
|
||||||
|
|
||||||
// Try to add a conflicting route that will trigger the strings.Cut path
|
// Try to add a conflicting route that will trigger the strings.Cut path
|
||||||
// This should panic with a wildcard conflict
|
// This should panic with a wildcard conflict
|
||||||
recv := catchPanic(func() {
|
recv := catchPanic(func() {
|
||||||
tree.addRoute("/user/:id/profile", fakeHandler("/user/:id/profile"))
|
tree.addRoute("/user/:id/profile", fakeHandler("/user/:id/profile"))
|
||||||
})
|
})
|
||||||
|
|
||||||
if recv == nil {
|
if recv == nil {
|
||||||
t.Error("Expected panic for wildcard conflict, but got none")
|
t.Error("Expected panic for wildcard conflict, but got none")
|
||||||
}
|
}
|
||||||
@ -539,28 +539,28 @@ func TestWildcardConflictWithStringsCut(t *testing.T) {
|
|||||||
func TestCatchAllConflictWithStringsCut(t *testing.T) {
|
func TestCatchAllConflictWithStringsCut(t *testing.T) {
|
||||||
// Test the strings.Cut usage in catch-all conflict detection (line 382 in tree.go)
|
// Test the strings.Cut usage in catch-all conflict detection (line 382 in tree.go)
|
||||||
tree := &node{}
|
tree := &node{}
|
||||||
|
|
||||||
// Add a route with a path segment
|
// Add a route with a path segment
|
||||||
tree.addRoute("/files/list", fakeHandler("/files/list"))
|
tree.addRoute("/files/list", fakeHandler("/files/list"))
|
||||||
|
|
||||||
// Try to add a catch-all route that conflicts
|
// Try to add a catch-all route that conflicts
|
||||||
// This should panic with a catch-all conflict
|
// This should panic with a catch-all conflict
|
||||||
recv := catchPanic(func() {
|
recv := catchPanic(func() {
|
||||||
tree.addRoute("/files/*filepath", fakeHandler("/files/*filepath"))
|
tree.addRoute("/files/*filepath", fakeHandler("/files/*filepath"))
|
||||||
})
|
})
|
||||||
|
|
||||||
if recv == nil {
|
if recv == nil {
|
||||||
t.Error("Expected panic for catch-all conflict, but got none")
|
t.Error("Expected panic for catch-all conflict, but got none")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Also test with an empty children case to cover line 382 when len(n.children) == 0
|
// Also test with an empty children case to cover line 382 when len(n.children) == 0
|
||||||
tree2 := &node{}
|
tree2 := &node{}
|
||||||
tree2.addRoute("/docs/", fakeHandler("/docs/"))
|
tree2.addRoute("/docs/", fakeHandler("/docs/"))
|
||||||
|
|
||||||
recv2 := catchPanic(func() {
|
recv2 := catchPanic(func() {
|
||||||
tree2.addRoute("/docs/*page", fakeHandler("/docs/*page"))
|
tree2.addRoute("/docs/*page", fakeHandler("/docs/*page"))
|
||||||
})
|
})
|
||||||
|
|
||||||
if recv2 == nil {
|
if recv2 == nil {
|
||||||
t.Error("Expected panic for catch-all conflict with empty children, but got none")
|
t.Error("Expected panic for catch-all conflict with empty children, but got none")
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user