Integrate real filesystem with interface abstraction
- Define pool.FileSystem interface in internal/io/pool/filesystem.go - Move DirEntry interface to internal/io/pool/types/types.go to break the pool <-> mock import cycle - Implement real.FileSystem with atomic writes (temp file + os.Rename) - Update mock.FileSystem to satisfy pool.FileSystem interface - Update worker pool tasks to accept pool.FileSystem interface - Update main.go to use RealFileSystem by default, with -root flag - Update all browser/editor/test references to types.DirEntry
This commit is contained in:
@@ -17,17 +17,17 @@ func TestLazyLoadingLargeDirectory(t *testing.T) {
|
||||
state.TotalEntries = 10000
|
||||
state.EntryHeight = 48.0
|
||||
state.VisibleCount = 10
|
||||
fs := mock.NewFileSystem()
|
||||
mfs := mock.NewFileSystem()
|
||||
wp := pool.NewWorkerPool(4)
|
||||
wp.Start()
|
||||
|
||||
// Populate mock filesystem with 10k entries
|
||||
fs.AddDir("/dir", time.Now())
|
||||
mfs.AddDir("/dir", time.Now())
|
||||
for i := 0; i < 10000; i++ {
|
||||
fs.AddFile(fmt.Sprintf("/dir/file_%d.txt", i), []byte("data"), time.Now())
|
||||
mfs.AddFile(fmt.Sprintf("/dir/file_%d.txt", i), []byte("data"), time.Now())
|
||||
}
|
||||
|
||||
bm, err := NewBrowserManager(state, wp, fs)
|
||||
bm, err := NewBrowserManager(state, wp, mfs)
|
||||
if err != nil {
|
||||
t.Fatalf("NewBrowserManager failed: %v", err)
|
||||
}
|
||||
@@ -88,17 +88,17 @@ func TestPrefetchOnScroll(t *testing.T) {
|
||||
state.TotalEntries = 1000
|
||||
state.EntryHeight = 48.0
|
||||
state.VisibleCount = 10
|
||||
fs := mock.NewFileSystem()
|
||||
mfs := mock.NewFileSystem()
|
||||
wp := pool.NewWorkerPool(4)
|
||||
wp.Start()
|
||||
|
||||
// Populate mock filesystem
|
||||
fs.AddDir("/dir", time.Now())
|
||||
mfs.AddDir("/dir", time.Now())
|
||||
for i := 0; i < 1000; i++ {
|
||||
fs.AddFile(fmt.Sprintf("/dir/file_%d.txt", i), []byte("data"), time.Now())
|
||||
mfs.AddFile(fmt.Sprintf("/dir/file_%d.txt", i), []byte("data"), time.Now())
|
||||
}
|
||||
|
||||
bm, err := NewBrowserManager(state, wp, fs)
|
||||
bm, err := NewBrowserManager(state, wp, mfs)
|
||||
if err != nil {
|
||||
t.Fatalf("NewBrowserManager failed: %v", err)
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"time"
|
||||
|
||||
"pad/internal/io/pool"
|
||||
"pad/internal/io/pool/mock"
|
||||
"pad/internal/io/pool/types"
|
||||
)
|
||||
|
||||
var ErrDirNotFound = fmt.Errorf("directory not found")
|
||||
@@ -14,10 +14,10 @@ var ErrDirNotFound = fmt.Errorf("directory not found")
|
||||
type BrowserManager struct {
|
||||
state *BrowserState
|
||||
workerPool *pool.WorkerPool
|
||||
fs *mock.FileSystem
|
||||
fs pool.FileSystem
|
||||
}
|
||||
|
||||
func NewBrowserManager(state *BrowserState, wp *pool.WorkerPool, fs *mock.FileSystem) (*BrowserManager, error) {
|
||||
func NewBrowserManager(state *BrowserState, wp *pool.WorkerPool, fs pool.FileSystem) (*BrowserManager, error) {
|
||||
return &BrowserManager{
|
||||
state: state,
|
||||
workerPool: wp,
|
||||
@@ -86,12 +86,12 @@ func (bm *BrowserManager) HandleResult(result pool.Result) {
|
||||
}
|
||||
|
||||
func (bm *BrowserManager) handleBuildIndexSuccess(result pool.Result) {
|
||||
fmt.Printf("handleBuildIndexSuccess: TotalEntries=%d\n", len(result.Data.([]mock.DirEntry)))
|
||||
fmt.Printf("handleBuildIndexSuccess: TotalEntries=%d\n", len(result.Data.([]types.DirEntry)))
|
||||
bm.state.Loading = false
|
||||
|
||||
// In the mock implementation, BuildIndexTask returns []mock.DirEntry.
|
||||
// In the mock implementation, BuildIndexTask returns []types.DirEntry.
|
||||
// We need to convert these to browser.Entry and build the SortIndex.
|
||||
entries := result.Data.([]mock.DirEntry)
|
||||
entries := result.Data.([]types.DirEntry)
|
||||
|
||||
var browserEntries []Entry
|
||||
// Add ".." entry if not at root
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"pad/internal/io/pool"
|
||||
"pad/internal/io/pool/mock"
|
||||
"pad/internal/io/pool/types"
|
||||
)
|
||||
|
||||
// TestNewBrowserManager verifies that a BrowserManager can be constructed
|
||||
@@ -109,7 +110,7 @@ func TestHandleResult_BuildIndexSuccess(t *testing.T) {
|
||||
result := pool.Result{
|
||||
TaskType: pool.TypeBuildIndex,
|
||||
Success: true,
|
||||
Data: []mock.DirEntry{},
|
||||
Data: []types.DirEntry{},
|
||||
}
|
||||
|
||||
bm.HandleResult(result)
|
||||
|
||||
@@ -12,9 +12,9 @@ import (
|
||||
// BrowserState.CurrentPath.
|
||||
func TestTapDirectory(t *testing.T) {
|
||||
state := NewBrowserState()
|
||||
fs := mock.NewFileSystem()
|
||||
mfs := mock.NewFileSystem()
|
||||
wp := pool.NewWorkerPool(1)
|
||||
bm, _ := NewBrowserManager(state, wp, fs)
|
||||
bm, _ := NewBrowserManager(state, wp, mfs)
|
||||
state.CurrentPath = "/root"
|
||||
|
||||
// Mock entries: a subdirectory "sub" and a file
|
||||
@@ -38,9 +38,9 @@ func TestTapDirectory(t *testing.T) {
|
||||
// BrowserState.CurrentPath to the parent directory.
|
||||
func TestTapUp(t *testing.T) {
|
||||
state := NewBrowserState()
|
||||
fs := mock.NewFileSystem()
|
||||
mfs := mock.NewFileSystem()
|
||||
wp := pool.NewWorkerPool(1)
|
||||
bm, _ := NewBrowserManager(state, wp, fs)
|
||||
bm, _ := NewBrowserManager(state, wp, mfs)
|
||||
state.CurrentPath = "/root/sub"
|
||||
|
||||
// Mock entries: ".." and a file
|
||||
@@ -64,9 +64,9 @@ func TestTapUp(t *testing.T) {
|
||||
// in the full directory listing.
|
||||
func TestTapWithSearchResults(t *testing.T) {
|
||||
state := NewBrowserState()
|
||||
fs := mock.NewFileSystem()
|
||||
mfs := mock.NewFileSystem()
|
||||
wp := pool.NewWorkerPool(1)
|
||||
bm, _ := NewBrowserManager(state, wp, fs)
|
||||
bm, _ := NewBrowserManager(state, wp, mfs)
|
||||
state.CurrentPath = "/root"
|
||||
|
||||
// Mock entries: 5 files, sorted by name
|
||||
@@ -98,9 +98,9 @@ func TestTapWithSearchResults(t *testing.T) {
|
||||
// search results resolves to the correct entries.
|
||||
func TestTapWithMultipleSearchResults(t *testing.T) {
|
||||
state := NewBrowserState()
|
||||
fs := mock.NewFileSystem()
|
||||
mfs := mock.NewFileSystem()
|
||||
wp := pool.NewWorkerPool(1)
|
||||
bm, _ := NewBrowserManager(state, wp, fs)
|
||||
bm, _ := NewBrowserManager(state, wp, mfs)
|
||||
state.CurrentPath = "/root"
|
||||
|
||||
// Mock entries: 5 files
|
||||
|
||||
Reference in New Issue
Block a user