Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tree_test.go with TestTreeFindNode test case #63

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions mux/tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,39 @@ func TestTreeMatch(t *testing.T) {
t.Fatalf("route did not match expected %s (%s)", "pl/blog/comments/123/new", commentNew.Name())
}
}

func TestTreeFindNode(t *testing.T) {
blog := NewNode("blog", 0)

search := NewNode("search", blog.MaxParamsSize())
page := NewNode("page", blog.MaxParamsSize())
posts := NewNode("posts", blog.MaxParamsSize())

blog.WithChildren(blog.Tree().withNode(search).sort())
blog.WithChildren(blog.Tree().withNode(page).sort())
blog.WithChildren(blog.Tree().withNode(posts).sort())

blog.WithChildren(blog.Tree().Compile())

tests := []struct {
name string
input string
expected Node
}{
{"Find existing node 1", "search", search},
{"Find existing node 2", "page", page},
{"Find existing node 3", "posts", posts},
{"Find non-existing node", "comments", nil},
{"Find with empty name", "", nil},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := blog.Tree().Find(tt.input)
if result != tt.expected {
t.Errorf("expected %v, got %v", tt.expected, result)
}
})
}
}