Fix logic of fetching torrents

This commit is contained in:
Ben Sarmiento
2024-05-06 10:48:01 +02:00
parent b6b59b22e6
commit ae94252156
11 changed files with 205 additions and 49 deletions

52
internal/fs/node_test.go Normal file
View File

@@ -0,0 +1,52 @@
package fs
import (
"testing"
)
// TestNewFileNode tests the creation of a new FileNode.
func TestNewFileNode(t *testing.T) {
node := NewFileNode("root", true)
if node.Name != "root" || !node.IsDir {
t.Errorf("NewFileNode failed to initialize properly")
}
}
// TestAddChild and TestListFiles tests adding children to a node and listing them.
func TestAddChild(t *testing.T) {
root := NewFileNode("root", true)
child1 := NewFileNode("child1", false)
child2 := NewFileNode("child2", true)
root.AddChild(child1)
root.AddChild(child2)
// Test if children are added properly
if _, ok := root.Children.Get("child1"); !ok {
t.Errorf("Failed to add child1")
}
if _, ok := root.Children.Get("child2"); !ok {
t.Errorf("Failed to add child2")
}
}
// TestGetFileNode tests retrieving a node from the file system based on a given path.
func TestGetFileNode(t *testing.T) {
root := NewFileNode("root", true)
child1 := NewFileNode("child1", false)
child2 := NewFileNode("child2", true)
root.AddChild(child1)
root.AddChild(child2)
// Retrieve node by path
resultNode := root.GetFileNode("child2")
if resultNode != child2 {
t.Errorf("GetFileNode failed to retrieve the correct node")
}
// Test non-existent path
if resultNode = root.GetFileNode("child3"); resultNode != nil {
t.Errorf("GetFileNode should return nil for non-existent node")
}
}