master
go 77 lines 1.55 KB
Raw
1 package testutils
2
3 import (
4 "os"
5 "os/exec"
6 "runtime"
7 "testing"
8 )
9
10 func RequiresDocker(t *testing.T) {
11 if os.Getenv("TEST_DOCKER") != "1" {
12 t.SkipNow()
13 }
14 }
15
16 func RequiresFUSE(t *testing.T) {
17 // Skip if FUSE tests are explicitly disabled
18 if os.Getenv("TEST_FUSE") == "0" {
19 t.Skip("FUSE tests disabled via TEST_FUSE=0")
20 }
21
22 // If TEST_FUSE=1 is set, always run (for backwards compatibility)
23 if os.Getenv("TEST_FUSE") == "1" {
24 return
25 }
26
27 // Auto-detect FUSE availability based on platform and tools
28 if !isFUSEAvailable(t) {
29 t.Skip("FUSE not available (no fusermount/umount found or unsupported platform)")
30 }
31 }
32
33 // isFUSEAvailable checks if FUSE is available on the current system
34 func isFUSEAvailable(t *testing.T) bool {
35 t.Helper()
36
37 // Check platform support
38 switch runtime.GOOS {
39 case "linux", "darwin", "freebsd", "openbsd", "netbsd":
40 // These platforms potentially support FUSE
41 case "windows":
42 // Windows has limited FUSE support via WinFsp, but skip for now
43 return false
44 default:
45 // Unknown platform, assume no FUSE support
46 return false
47 }
48
49 // Check for required unmount tools
50 var unmountCmd string
51 if runtime.GOOS == "linux" {
52 unmountCmd = "fusermount"
53 } else {
54 unmountCmd = "umount"
55 }
56
57 _, err := exec.LookPath(unmountCmd)
58 return err == nil
59 }
60
61 func RequiresExpensive(t *testing.T) {
62 if os.Getenv("TEST_EXPENSIVE") == "1" || testing.Short() {
63 t.SkipNow()
64 }
65 }
66
67 func RequiresPlugins(t *testing.T) {
68 if os.Getenv("TEST_PLUGIN") != "1" {
69 t.SkipNow()
70 }
71 }
72
73 func RequiresLinux(t *testing.T) {
74 if runtime.GOOS != "linux" {
75 t.SkipNow()
76 }
77 }