github.com/djenriquez/nomad-1@v0.8.1/client/testutil/driver_compatible.go (about) 1 package testutil 2 3 import ( 4 "os/exec" 5 "runtime" 6 "syscall" 7 "testing" 8 ) 9 10 // RequireRoot skips tests unless running on a Unix as root. 11 func RequireRoot(t *testing.T) { 12 if syscall.Geteuid() != 0 { 13 t.Skip("Must run as root on Unix") 14 } 15 } 16 17 func ExecCompatible(t *testing.T) { 18 if runtime.GOOS != "linux" || syscall.Geteuid() != 0 { 19 t.Skip("Test only available running as root on linux") 20 } 21 } 22 23 func JavaCompatible(t *testing.T) { 24 if runtime.GOOS == "linux" && syscall.Geteuid() != 0 { 25 t.Skip("Test only available when running as root on linux") 26 } 27 } 28 29 func QemuCompatible(t *testing.T) { 30 // Check if qemu exists 31 bin := "qemu-system-x86_64" 32 if runtime.GOOS == "windows" { 33 bin = "qemu-img" 34 } 35 _, err := exec.Command(bin, "--version").CombinedOutput() 36 if err != nil { 37 t.Skip("Must have Qemu installed for Qemu specific tests to run") 38 } 39 } 40 41 func RktCompatible(t *testing.T) { 42 if runtime.GOOS == "windows" || syscall.Geteuid() != 0 { 43 t.Skip("Must be root on non-windows environments to run test") 44 } 45 // else see if rkt exists 46 _, err := exec.Command("rkt", "version").CombinedOutput() 47 if err != nil { 48 t.Skip("Must have rkt installed for rkt specific tests to run") 49 } 50 } 51 52 func MountCompatible(t *testing.T) { 53 if runtime.GOOS == "windows" { 54 t.Skip("Windows does not support mount") 55 } 56 57 if syscall.Geteuid() != 0 { 58 t.Skip("Must be root to run test") 59 } 60 }