master
go 58 lines 1.47 KB
Raw
1 // FUSE availability detection. go-fuse only builds on linux, darwin, and freebsd.
2 //go:build (linux || darwin || freebsd) && !nofuse
3
4 package fusetest
5
6 import (
7 "os"
8 "os/exec"
9 "runtime"
10 "testing"
11 )
12
13 // fuseFlagFromEnv returns the value of TEST_FUSE if set, or empty string.
14 // Also checks the legacy TEST_NO_FUSE for backwards compatibility.
15 func fuseFlagFromEnv() string {
16 if v := os.Getenv("TEST_FUSE"); v != "" {
17 return v
18 }
19 // Legacy: TEST_NO_FUSE=1 is equivalent to TEST_FUSE=0
20 if os.Getenv("TEST_NO_FUSE") == "1" {
21 return "0"
22 }
23 return ""
24 }
25
26 // fuseAvailable checks whether FUSE is likely to work on this system
27 // and skips with a helpful message if not.
28 //
29 // hanwen/go-fuse supports Linux, macOS, and FreeBSD. NetBSD and OpenBSD
30 // are not supported: NetBSD uses PUFFS (a different protocol) and
31 // OpenBSD's FUSE support is not compatible with go-fuse's mount mechanism.
32 func fuseAvailable(t *testing.T) bool {
33 t.Helper()
34
35 switch runtime.GOOS {
36 case "linux", "darwin", "freebsd":
37 default:
38 t.Skip("FUSE not supported on", runtime.GOOS)
39 return false
40 }
41
42 if runtime.GOOS == "linux" {
43 // go-fuse tries fusermount3 first, then fusermount.
44 if _, err := exec.LookPath("fusermount"); err == nil {
45 return true
46 }
47 if _, err := exec.LookPath("fusermount3"); err == nil {
48 return true
49 }
50 t.Skip("neither fusermount nor fusermount3 found in PATH")
51 return false
52 }
53
54 if _, err := exec.LookPath("umount"); err != nil {
55 t.Skip("umount not found in PATH")
56 }
57 return true
58 }