Test that a mounted tree lists and reads its files under its mount

This commit is contained in:
2026-10-11 15:45:31 +02:00
committed by Lillem4n
parent e8f5fd47d5
commit 5b1f80c350
+17 -3
View File
@@ -2,6 +2,7 @@ package datafiles
import (
"errors"
"io/fs"
"os"
"path/filepath"
"reflect"
@@ -176,10 +177,23 @@ func TestAMountedDirNamesItsFilesWhereTheyAreOnDisk(t *testing.T) {
}
}
func TestAMountedTreeIsAValidFS(t *testing.T) {
func TestAMountedTreeListsAndReadsUnderItsMount(t *testing.T) {
m := mounted{fsys: fstest.MapFS{"a.json": {Data: []byte(`"x"`)}, "sub/b.json": {Data: []byte(`"y"`)}}, at: "my/data"}
if err := fstest.TestFS(m, "my/data/a.json", "my/data/sub/b.json"); err != nil {
t.Fatal(err)
for dir, want := range map[string][]string{".": {"my"}, "my": {"data"}, "my/data": {"a.json", "sub"}, "my/data/sub": {"b.json"}} {
entries, err := fs.ReadDir(m, dir)
var got []string
for _, e := range entries {
got = append(got, e.Name())
}
if err != nil || !reflect.DeepEqual(got, want) {
t.Errorf("ReadDir(%q) = %v, %v, want %v", dir, got, err, want)
}
}
if b, err := fs.ReadFile(m, "my/data/sub/b.json"); err != nil || string(b) != `"y"` {
t.Errorf(`ReadFile("my/data/sub/b.json") = %q, %v, want "y"`, b, err)
}
if _, err := fs.ReadFile(m, "other/a.json"); !errors.Is(err, fs.ErrNotExist) {
t.Errorf(`ReadFile("other/a.json") = %v, want it not to exist`, err)
}
}