53 lines
1.3 KiB
Go
53 lines
1.3 KiB
Go
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")
|
|
}
|
|
}
|