github.com/bananabytelabs/wazero@v0.0.0-20240105073314-54b22a776da8/internal/testing/fs/fs.go (about) 1 package testfs 2 3 import "io/fs" 4 5 // compile-time check to ensure File implements fs.File 6 var _ fs.File = &File{} 7 8 // compile-time check to ensure FS implements fs.FS 9 var _ fs.FS = &FS{} 10 11 // FS emulates fs.FS. Note: the path (map key) cannot begin with "/"! 12 type FS map[string]*File 13 14 // Open implements the same method as documented on fs.FS, except it doesn't 15 // validate the path. 16 func (f FS) Open(name string) (fs.File, error) { 17 if file, ok := f[name]; !ok { 18 return nil, &fs.PathError{Op: "open", Path: name, Err: fs.ErrNotExist} 19 } else { 20 return file, nil 21 } 22 } 23 24 type File struct{ CloseErr error } 25 26 func (f *File) Close() error { return f.CloseErr } 27 func (f *File) Stat() (fs.FileInfo, error) { return nil, nil } 28 func (f *File) Read(_ []byte) (int, error) { return 0, nil } 29 func (f *File) Seek(_ int64, _ int) (int64, error) { return 0, nil }