-
Notifications
You must be signed in to change notification settings - Fork 270
/
fuse_test.go
66 lines (59 loc) · 1.71 KB
/
fuse_test.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package fuse_test
import (
"os"
"runtime"
"testing"
"bazil.org/fuse"
)
func getFeatures(t *testing.T, opts ...fuse.MountOption) fuse.InitFlags {
tmp, err := os.MkdirTemp("", "fusetest")
if err != nil {
t.Fatalf("error creating temp dir: %v", err)
}
defer func() {
if err := os.RemoveAll(tmp); err != nil {
t.Errorf("error cleaning temp dir: %v", err)
}
}()
conn, err := fuse.Mount(tmp, opts...)
if err != nil {
t.Fatalf("error mounting: %v", err)
}
defer func() {
if err := conn.Close(); err != nil {
t.Errorf("error closing FUSE connection: %v", err)
}
if err := fuse.Unmount(tmp); err != nil {
t.Errorf("error unmounting: %v", err)
}
}()
return conn.Features()
}
func TestFeatures(t *testing.T) {
run := func(name string, want, notwant fuse.InitFlags, opts ...fuse.MountOption) {
t.Run(name, func(t *testing.T) {
if runtime.GOOS == "freebsd" {
if want&fuse.InitFlockLocks != 0 {
t.Skip("FreeBSD FUSE does not implement Flock locks")
}
}
got := getFeatures(t, opts...)
t.Logf("features: %v", got)
missing := want &^ got
if missing != 0 {
t.Errorf("missing: %v", missing)
}
extra := got & notwant
if extra != 0 {
t.Errorf("extra: %v", extra)
}
})
}
run("bare", 0, fuse.InitPOSIXLocks|fuse.InitFlockLocks)
run("LockingFlock", fuse.InitFlockLocks, 0, fuse.LockingFlock())
run("LockingPOSIX", fuse.InitPOSIXLocks, 0, fuse.LockingPOSIX())
run("AsyncRead", fuse.InitAsyncRead, 0, fuse.AsyncRead())
run("WritebackCache", fuse.InitWritebackCache, 0, fuse.WritebackCache())
run("CacheSymlinks", fuse.InitCacheSymlinks, 0, fuse.CacheSymlinks())
run("ExplicitInvalidateData", fuse.InitExplicitInvalidateData, 0, fuse.ExplicitInvalidateData())
}