Debian Codegraph @

fs/fstestutil/testfs.go

raw symbols SCIP
1 package fstestutil
2
3 import (
4 "os"
5
6 "github.com/jacobsa/bazilfuse/fs"
7 "golang.org/x/net/context"
8 )
9
10 // SimpleFS is a trivial FS that just implements the Root method.
11 type SimpleFS struct {
12 Node fs.Node
13 }
14
15 var _ = fs.FS(SimpleFS{})
16
17 func (f SimpleFS) Root() (fs.Node, error) {
18 return f.Node, nil
19 }
20
21 // File can be embedded in a struct to make it look like a file.
22 type File struct{}
23
24 func (f File) Attr(ctx context.Context, a *fuse.Attr) error {
25 a.Mode = 0666
26 return nil
27 }
28
29 // Dir can be embedded in a struct to make it look like a directory.
30 type Dir struct{}
31
32 func (f Dir) Attr(ctx context.Context, a *fuse.Attr) error {
33 a.Mode = os.ModeDir | 0777
34 return nil
35 }
36
37 // ChildMap is a directory with child nodes looked up from a map.
38 type ChildMap map[string]fs.Node
39
40 var _ = fs.Node(ChildMap{})
41 var _ = fs.NodeStringLookuper(ChildMap{})
42
43 func (f ChildMap) Attr(ctx context.Context, a *fuse.Attr) error {
44 a.Mode = os.ModeDir | 0777
45 return nil
46 }
47
48 func (f ChildMap) Lookup(ctx context.Context, name string) (fs.Node, error) {
49 child, ok := f[name]
50 if !ok {
51 return nil, fuse.ENOENT
52 }
53 return child, nil
54 }