From 9852cfaf6c44b9e2960719feb57c6d0e53598f3c Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 25 May 2024 23:57:29 +0300 Subject: add memoryfs vfs implementation --- internal/vfs/memoryfs.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'internal/vfs/memoryfs.go') diff --git a/internal/vfs/memoryfs.go b/internal/vfs/memoryfs.go index 22b1611..6250e39 100644 --- a/internal/vfs/memoryfs.go +++ b/internal/vfs/memoryfs.go @@ -5,6 +5,7 @@ import ( "strings" ) +// VFS implementaion especially for unit testing. type MemoryFS map[string][]byte func (fs MemoryFS) ReadFile(filePath string) ([]byte, error) { @@ -14,7 +15,7 @@ func (fs MemoryFS) ReadFile(filePath string) ([]byte, error) { return []byte{}, fmt.Errorf("no such file path: %s", filePath) } -func (fs MemoryFS) SaveFile(filePath string, bytes []byte) error { +func (fs MemoryFS) WriteFile(filePath string, bytes []byte) error { fs[filePath] = bytes return nil } @@ -23,7 +24,7 @@ func (fs MemoryFS) FindFiles(dataDir, suffix string) ([]string, error) { var filePaths []string for filePath := range fs { - if !strings.HasSuffix(filePath, suffix) { + if !strings.HasPrefix(filePath, dataDir) || !strings.HasSuffix(filePath, suffix) { continue } filePaths = append(filePaths, filePath) -- cgit v1.2.3