forked from tetratelabs/wazero
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fs.go
29 lines (22 loc) · 887 Bytes
/
fs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package testfs
import "io/fs"
// compile-time check to ensure File implements fs.File
var _ fs.File = &File{}
// compile-time check to ensure FS implements fs.FS
var _ fs.FS = &FS{}
// FS emulates fs.FS. Note: the path (map key) cannot begin with "/"!
type FS map[string]*File
// Open implements the same method as documented on fs.FS, except it doesn't
// validate the path.
func (f FS) Open(name string) (fs.File, error) {
if file, ok := f[name]; !ok {
return nil, &fs.PathError{Op: "open", Path: name, Err: fs.ErrNotExist}
} else {
return file, nil
}
}
type File struct{ CloseErr error }
func (f *File) Close() error { return f.CloseErr }
func (f *File) Stat() (fs.FileInfo, error) { return nil, nil }
func (f *File) Read(_ []byte) (int, error) { return 0, nil }
func (f *File) Seek(_ int64, _ int) (int64, error) { return 0, nil }