summaryrefslogtreecommitdiff
path: root/internal/vfs/memoryfs_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2024-09-21 14:03:45 +0300
committerPaul Buetow <paul@buetow.org>2024-09-21 14:03:45 +0300
commitdff4d455e07d639b82a0bed814f41d0656e9b6d0 (patch)
tree56289a6fd80a00a9724992ab9cb8b3d7215ebedf /internal/vfs/memoryfs_test.go
parent780ade3dc066afb8a43be824373414f3d316ebd6 (diff)
cleanup
Diffstat (limited to 'internal/vfs/memoryfs_test.go')
-rw-r--r--internal/vfs/memoryfs_test.go108
1 files changed, 0 insertions, 108 deletions
diff --git a/internal/vfs/memoryfs_test.go b/internal/vfs/memoryfs_test.go
deleted file mode 100644
index f6a9cf1..0000000
--- a/internal/vfs/memoryfs_test.go
+++ /dev/null
@@ -1,108 +0,0 @@
-package vfs
-
-import (
- "slices"
- "strings"
- "testing"
-)
-
-func TestMemoryFS(t *testing.T) {
- t.Parallel()
- fs := make(MemoryFS)
-
- writeFiles := map[string]string{
- "/data/dir/foo.json": "hello world",
- "/data/dir/subdir/bar.json": "hello solar system",
- "/data/dir/subdir/baz.json": "hello universe",
- "/data/dir/subdir/bay.txt": "hello bar keeper",
- }
-
- for path, content := range writeFiles {
- bytes := []byte(content)
- _ = fs.WriteFile(path, bytes)
- }
-
- t.Run("files are there", func(t *testing.T) {
- testFilesAreThere(t, fs, writeFiles)
- })
-
- t.Run("file is not there", func(t *testing.T) {
- testFileNotThere(t, fs, "/dennis.rodman.txt")
- })
-
- t.Run("find json files", func(t *testing.T) {
- testFindFiles(t, fs, writeFiles, "/data/dir/subdir", ".json", 2)
- })
-
-}
-
-func TestPassByValue(t *testing.T) {
- t.Parallel()
- fs := make(MemoryFS)
-
- writeFiles := map[string]string{
- "/data/dir/foo.json": "hello world",
- "/data/dir/subdir/bar.json": "hello solar system",
- "/data/dir/subdir/baz.json": "hello universe",
- "/data/dir/subdir/bay.txt": "hello bar keeper",
- }
-
- // Should work, as the underlying data type is a map.
- func(fs MemoryFS) {
- for path, content := range writeFiles {
- bytes := []byte(content)
- _ = fs.WriteFile(path, bytes)
- }
- }(fs)
-
- t.Run("files are there", func(t *testing.T) {
- testFilesAreThere(t, fs, writeFiles)
- })
-}
-
-func testFilesAreThere(t *testing.T, fs MemoryFS, writeFiles map[string]string) {
- for path, content := range writeFiles {
- bytes, err := fs.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, fs MemoryFS, filePath string) {
- _, err := fs.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, fs MemoryFS, writeFiles map[string]string, dataDir, suffix string, count int) {
- filePaths, err := fs.FindFiles(dataDir, suffix)
- if err != nil {
- t.Error(err)
- return
- }
-
- if len(filePaths) != count {
- t.Error("expected", count, "json files, but got", filePaths)
- return
- }
-
- for filePath := range writeFiles {
- if !strings.HasPrefix(filePath, dataDir) || !strings.HasSuffix(filePath, suffix) {
- continue
- }
-
- if !slices.Contains(filePaths, filePath) {
- t.Error("expected file", filePath, "to be there, but it isn't in", filePaths)
- return
- }
- }
-}