diff options
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/types/entry.go | 4 | ||||
| -rw-r--r-- | internal/vfs/memoryfs_test.go | 42 |
2 files changed, 31 insertions, 15 deletions
diff --git a/internal/types/entry.go b/internal/types/entry.go index c2ccb82..af1e991 100644 --- a/internal/types/entry.go +++ b/internal/types/entry.go @@ -72,7 +72,9 @@ func NewEntryFromFile(filePath string, vfsToUse ...vfs.VFS) (Entry, error) { if err != err { return Entry{}, err } - return NewEntry(bytes) + e, err := NewEntry(bytes) + e.vfs = vfs + return e, err } func NewEntryFromCopy(other Entry) (Entry, error) { diff --git a/internal/vfs/memoryfs_test.go b/internal/vfs/memoryfs_test.go index 46607e0..a1d392e 100644 --- a/internal/vfs/memoryfs_test.go +++ b/internal/vfs/memoryfs_test.go @@ -26,9 +26,37 @@ func TestMemoryFS(t *testing.T) { testFilesAreThere(t, vfs, writeFiles) }) + t.Run("file is not there", func(t *testing.T) { + testFileNotThere(t, vfs, "/dennis.rodman.txt") + }) + t.Run("find json files", func(t *testing.T) { testFindFiles(t, vfs, writeFiles, "/data/dir/subdir", ".json", 2) }) + +} + +func testFilesAreThere(t *testing.T, vfs VFS, writeFiles map[string]string) { + for path, content := range writeFiles { + bytes, err := vfs.ReadFile(path) + if err != nil { + t.Error(err) + return + } + if content != string(bytes) { + t.Error("expected", content, "in file", path, "but got", string(bytes)) + return + } + } +} + +func testFileNotThere(t *testing.T, vfs VFS, filePath string) { + _, err := vfs.ReadFile(filePath) + if err == nil { + t.Error("expected file", filePath, "not to be there, but it is") + return + } + t.Log("file", filePath, "not there as expected:", err) } func testFindFiles(t *testing.T, vfs VFS, writeFiles map[string]string, dataDir, suffix string, count int) { @@ -54,17 +82,3 @@ func testFindFiles(t *testing.T, vfs VFS, writeFiles map[string]string, dataDir, } } } - -func testFilesAreThere(t *testing.T, vfs VFS, writeFiles map[string]string) { - for path, content := range writeFiles { - bytes, err := vfs.ReadFile(path) - if err != nil { - t.Error(err) - return - } - if content != string(bytes) { - t.Error("expected", content, "in file", path, "but got", string(bytes)) - return - } - } -} |
