fix(tree): correctly expand the capacity of params (#3502)
This commit is contained in:
+31
-3
@@ -893,9 +893,9 @@ func TestTreeInvalidNodeType(t *testing.T) {
|
||||
|
||||
func TestTreeInvalidParamsType(t *testing.T) {
|
||||
tree := &node{}
|
||||
tree.wildChild = true
|
||||
tree.children = append(tree.children, &node{})
|
||||
tree.children[0].nType = 2
|
||||
// add a child with wildcard
|
||||
route := "/:path"
|
||||
tree.addRoute(route, fakeHandler(route))
|
||||
|
||||
// set invalid Params type
|
||||
params := make(Params, 0)
|
||||
@@ -904,6 +904,34 @@ func TestTreeInvalidParamsType(t *testing.T) {
|
||||
tree.getValue("/test", ¶ms, getSkippedNodes(), false)
|
||||
}
|
||||
|
||||
func TestTreeExpandParamsCapacity(t *testing.T) {
|
||||
data := []struct {
|
||||
path string
|
||||
}{
|
||||
{"/:path"},
|
||||
{"/*path"},
|
||||
}
|
||||
|
||||
for _, item := range data {
|
||||
tree := &node{}
|
||||
tree.addRoute(item.path, fakeHandler(item.path))
|
||||
params := make(Params, 0)
|
||||
|
||||
value := tree.getValue("/test", ¶ms, getSkippedNodes(), false)
|
||||
|
||||
if value.params == nil {
|
||||
t.Errorf("Expected %s params to be set, but they weren't", item.path)
|
||||
continue
|
||||
}
|
||||
|
||||
if len(*value.params) != 1 {
|
||||
t.Errorf("Wrong number of %s params: got %d, want %d",
|
||||
item.path, len(*value.params), 1)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestTreeWildcardConflictEx(t *testing.T) {
|
||||
conflicts := [...]struct {
|
||||
route string
|
||||
|
||||
Reference in New Issue
Block a user