summaryrefslogtreecommitdiff
path: root/internal/vfs/memoryfs.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2024-05-25 23:57:29 +0300
committerPaul Buetow <paul@buetow.org>2024-05-25 23:57:29 +0300
commit9852cfaf6c44b9e2960719feb57c6d0e53598f3c (patch)
tree9397202cb143503d49a5b226ce5be8fcfa202be8 /internal/vfs/memoryfs.go
parent6e631b4ccbe71299137469a69900b874d709fe35 (diff)
add memoryfs vfs implementation
Diffstat (limited to 'internal/vfs/memoryfs.go')
-rw-r--r--internal/vfs/memoryfs.go5
1 files changed, 3 insertions, 2 deletions
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)