github.com/bigcommerce/nomad@v0.9.3-bc/client/testutil/driver_compatible.go (about) 1 package testutil 2 3 import ( 4 "os/exec" 5 "runtime" 6 "sync" 7 "syscall" 8 "testing" 9 10 "github.com/hashicorp/nomad/client/fingerprint" 11 ) 12 13 // RequireRoot skips tests unless running on a Unix as root. 14 func RequireRoot(t *testing.T) { 15 if syscall.Geteuid() != 0 { 16 t.Skip("Must run as root on Unix") 17 } 18 } 19 20 func ExecCompatible(t *testing.T) { 21 if runtime.GOOS != "linux" || syscall.Geteuid() != 0 { 22 t.Skip("Test only available running as root on linux") 23 } 24 CgroupCompatible(t) 25 } 26 27 func JavaCompatible(t *testing.T) { 28 if runtime.GOOS == "linux" && syscall.Geteuid() != 0 { 29 t.Skip("Test only available when running as root on linux") 30 } 31 } 32 33 func QemuCompatible(t *testing.T) { 34 // Check if qemu exists 35 bin := "qemu-system-x86_64" 36 if runtime.GOOS == "windows" { 37 bin = "qemu-img" 38 } 39 _, err := exec.Command(bin, "--version").CombinedOutput() 40 if err != nil { 41 t.Skip("Must have Qemu installed for Qemu specific tests to run") 42 } 43 } 44 45 func CgroupCompatible(t *testing.T) { 46 mount, err := fingerprint.FindCgroupMountpointDir() 47 if err != nil || mount == "" { 48 t.Skipf("Failed to find cgroup mount: %v %v", mount, err) 49 } 50 } 51 52 var rktExists bool 53 var rktOnce sync.Once 54 55 func RktCompatible(t *testing.T) { 56 if runtime.GOOS != "linux" || syscall.Geteuid() != 0 { 57 t.Skip("Must be root on Linux to run test") 58 } 59 60 // else see if rkt exists 61 rktOnce.Do(func() { 62 _, err := exec.Command("rkt", "version").CombinedOutput() 63 if err == nil { 64 rktExists = true 65 } 66 }) 67 68 if !rktExists { 69 t.Skip("Must have rkt installed for rkt specific tests to run") 70 } 71 } 72 73 func MountCompatible(t *testing.T) { 74 if runtime.GOOS == "windows" { 75 t.Skip("Windows does not support mount") 76 } 77 78 if syscall.Geteuid() != 0 { 79 t.Skip("Must be root to run test") 80 } 81 }