I am trying to use fstest.MapFS to help with testing, but I noticed the mapfs implementation of
ReadDir does not set the name field which is quite problematic as I rely on that in my code.
Example Test Code:
t.Run("some test", func(t *testing.T) {
fs := fstest.MapFS{
"/some/long/test/path_hi_there": {Mode: fs.ModeDir},
}
err := VerifyDir(fs, "/some/long/test/path_hi_there")
if err != nil {
fmt.Println("unexpected error %+v", err)
}
})
Snippet of Code:func VerifyDir(fsys fs.FS, dir string) error {
entries, err := fs.ReadDir(fsys, ".")
if err != nil {
return err
}
for _, entry := range entries {
if !entry.IsDir() {
continue
}
fmt.Println("expected entry.Name() to not be empty:", entry.Name())
path := filepath.Join(dir, entry.Name())
// do stuff with path...
}
return nil
}
Any ideas around this? Any practical examples of using fstest.MapFS to learn from?