On Wed, Mar 23, 2022 at 2:01 PM Kalen Krempely <kale...@gmail.com> wrote: > > 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?
As far as I can tell testing.MapFS.ReadDir does return values for which the Name method returns a non-empty string. Can you show a complete, stand-alone, program that demonstrates the problem you are describing? Thanks. Note that in normal use the strings used as names when initialization a testing.MapFS should not start with a slash. See https://pkg.go.dev/io/fs#ValidPath. Ian -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcUQvBJK9F3ub5%2Brfpvoo3vLnmAmG_ffp5Ec7SCpRqjwMg%40mail.gmail.com.