File: fuse_test.go

package info (click to toggle)
golang-github-anacrolix-fuse 0.3.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,000 kB
  • sloc: makefile: 5; sh: 3
file content (69 lines) | stat: -rw-r--r-- 1,658 bytes parent folder | download
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
67
68
69
package fuse_test

import (
	"io/ioutil"
	"os"
	"runtime"
	"testing"

	_ "github.com/anacrolix/envpprof"
	"github.com/anacrolix/fuse"
)

func getFeatures(t *testing.T, opts ...fuse.MountOption) fuse.InitFlags {
	tmp, err := ioutil.TempDir("", "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)
		}
	}()

	defer func() {
		err := fuse.Unmount(tmp)
		if err != nil {
			t.Logf("error unmounting: %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)
		}
	}()

	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())
}