/
testfs.go
48 lines (35 loc) · 1.15 KB
/
testfs.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package fstestutil
import (
"os"
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/bazil.org/fuse"
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/bazil.org/fuse/fs"
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
)
// SimpleFS is a trivial FS that just implements the Root method.
type SimpleFS struct {
Node fs.Node
}
var _ = fs.FS(SimpleFS{})
func (f SimpleFS) Root() (fs.Node, error) {
return f.Node, nil
}
// File can be embedded in a struct to make it look like a file.
type File struct{}
func (f File) Attr() fuse.Attr { return fuse.Attr{Mode: 0666} }
// Dir can be embedded in a struct to make it look like a directory.
type Dir struct{}
func (f Dir) Attr() fuse.Attr { return fuse.Attr{Mode: os.ModeDir | 0777} }
// ChildMap is a directory with child nodes looked up from a map.
type ChildMap map[string]fs.Node
var _ = fs.Node(ChildMap{})
var _ = fs.NodeStringLookuper(ChildMap{})
func (f ChildMap) Attr() fuse.Attr {
return fuse.Attr{Mode: os.ModeDir | 0777}
}
func (f ChildMap) Lookup(ctx context.Context, name string) (fs.Node, error) {
child, ok := f[name]
if !ok {
return nil, fuse.ENOENT
}
return child, nil
}