-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfuse_adapter_test.go
More file actions
144 lines (118 loc) · 3.45 KB
/
fuse_adapter_test.go
File metadata and controls
144 lines (118 loc) · 3.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
//go:build linux || darwin
// +build linux darwin
package toolfs
import (
"os"
"path/filepath"
"testing"
)
// TestFUSEAdapterCompilation tests that the FUSE adapter compiles correctly
// This is a basic compilation test - actual FUSE mounting requires root/admin privileges
func TestFUSEAdapterCompilation(t *testing.T) {
// Create a temporary ToolFS instance
fs := NewToolFS("/toolfs")
// Create a temporary directory for mounting (we won't actually mount)
tmpDir, err := os.MkdirTemp("", "toolfs-fuse-test-*")
if err != nil {
t.Fatalf("Failed to create temp dir: %v", err)
}
defer os.RemoveAll(tmpDir)
// Test that we can create the root node
root := NewToolFSRoot(fs)
if root == nil {
t.Fatal("NewToolFSRoot returned nil")
}
if root.toolfs != fs {
t.Error("Root node's toolfs reference is incorrect")
}
}
// TestNormalizeMountPoint tests the normalizeMountPoint function
func TestNormalizeMountPoint(t *testing.T) {
fs := NewToolFS("/toolfs")
tests := []struct {
mountPoint string
expected string
}{
{"/toolfs/data", "data"},
{"/toolfs/memory", "memory"},
{"/toolfs/rag", "rag"},
{"/toolfs", ""},
{"/toolfs/skills/myskill", "skills"},
}
for _, tt := range tests {
t.Run(tt.mountPoint, func(t *testing.T) {
result := fs.normalizeMountPoint(tt.mountPoint)
if result != tt.expected {
t.Errorf("normalizeMountPoint(%q) = %q, want %q", tt.mountPoint, result, tt.expected)
}
})
}
}
// TestFUSEDirStructure tests that directory structure is correctly represented
func TestFUSEDirStructure(t *testing.T) {
fs := NewToolFS("/toolfs")
// Mount a test directory
tmpDir, err := os.MkdirTemp("", "toolfs-test-*")
if err != nil {
t.Fatalf("Failed to create temp dir: %v", err)
}
defer os.RemoveAll(tmpDir)
// Create a test file
testFile := filepath.Join(tmpDir, "test.txt")
if err := os.WriteFile(testFile, []byte("test content"), 0644); err != nil {
t.Fatalf("Failed to create test file: %v", err)
}
// Mount the directory
err = fs.MountLocal("/toolfs/test", tmpDir, false)
if err != nil {
t.Fatalf("Failed to mount: %v", err)
}
// Test that we can list the directory
entries, err := fs.ListDir("/toolfs/test")
if err != nil {
t.Fatalf("Failed to list directory: %v", err)
}
if len(entries) == 0 {
t.Error("Expected at least one entry in mounted directory")
}
// Test that we can read the file
content, err := fs.ReadFile("/toolfs/test/test.txt")
if err != nil {
t.Fatalf("Failed to read file: %v", err)
}
if string(content) != "test content" {
t.Errorf("File content mismatch: got %q, want %q", string(content), "test content")
}
}
// TestFUSEMemoryAccess tests that memory entries can be accessed
func TestFUSEMemoryAccess(t *testing.T) {
fs := NewToolFS("/toolfs")
// Write to memory
err := fs.WriteFile("/toolfs/memory/test-entry", []byte("memory content"))
if err != nil {
t.Fatalf("Failed to write to memory: %v", err)
}
// Read from memory
content, err := fs.ReadFile("/toolfs/memory/test-entry")
if err != nil {
t.Fatalf("Failed to read from memory: %v", err)
}
if string(content) == "" {
t.Error("Memory content is empty")
}
// List memory entries
entries, err := fs.ListDir("/toolfs/memory")
if err != nil {
t.Fatalf("Failed to list memory: %v", err)
}
found := false
for _, entry := range entries {
if entry == "test-entry" || entry == "test-entry/" {
found = true
break
}
}
if !found {
t.Errorf("Memory entry not found in list: %v", entries)
}
}