diff options
| author | Paul Buetow <paul@buetow.org> | 2024-05-26 00:07:17 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2024-05-26 00:07:17 +0300 |
| commit | 9be6694a4a70e06be713033145f763e9d7f86295 (patch) | |
| tree | 8f27b47097f92c272706b4b12b6a85459af52116 /internal/vfs | |
| parent | 9852cfaf6c44b9e2960719feb57c6d0e53598f3c (diff) | |
add negative memory fs test as well
Diffstat (limited to 'internal/vfs')
| -rw-r--r-- | internal/vfs/memoryfs_test.go | 42 |
1 files changed, 28 insertions, 14 deletions
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 - } - } -} |
