Skip to content

Commit b9cbbae

Browse files
authored
Merge pull request #63 from WheeskyJack/WheeskyJack-TestTreeFindNode
Update tree_test.go with TestTreeFindNode test case
2 parents 553bff7 + 28e40cb commit b9cbbae

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

mux/tree_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,39 @@ func TestTreeMatch(t *testing.T) {
4343
t.Fatalf("route did not match expected %s (%s)", "pl/blog/comments/123/new", commentNew.Name())
4444
}
4545
}
46+
47+
func TestTreeFindNode(t *testing.T) {
48+
blog := NewNode("blog", 0)
49+
50+
search := NewNode("search", blog.MaxParamsSize())
51+
page := NewNode("page", blog.MaxParamsSize())
52+
posts := NewNode("posts", blog.MaxParamsSize())
53+
54+
blog.WithChildren(blog.Tree().withNode(search).sort())
55+
blog.WithChildren(blog.Tree().withNode(page).sort())
56+
blog.WithChildren(blog.Tree().withNode(posts).sort())
57+
58+
blog.WithChildren(blog.Tree().Compile())
59+
60+
tests := []struct {
61+
name string
62+
input string
63+
expected Node
64+
}{
65+
{"Find existing node 1", "search", search},
66+
{"Find existing node 2", "page", page},
67+
{"Find existing node 3", "posts", posts},
68+
{"Find non-existing node", "comments", nil},
69+
{"Find with empty name", "", nil},
70+
}
71+
72+
for _, tt := range tests {
73+
t.Run(tt.name, func(t *testing.T) {
74+
result := blog.Tree().Find(tt.input)
75+
if result != tt.expected {
76+
t.Errorf("expected %v, got %v", tt.expected, result)
77+
}
78+
})
79+
}
80+
}
81+

0 commit comments

Comments
 (0)