github.com/emate/nomad@v0.8.2-wo-binpacking/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 11 // RequireRoot skips tests unless running on a Unix as root. 12 func RequireRoot(t *testing.T) { 13 if syscall.Geteuid() != 0 { 14 t.Skip("Must run as root on Unix") 15 } 16 } 17 18 func ExecCompatible(t *testing.T) { 19 if runtime.GOOS != "linux" || syscall.Geteuid() != 0 { 20 t.Skip("Test only available running as root on linux") 21 } 22 } 23 24 func JavaCompatible(t *testing.T) { 25 if runtime.GOOS == "linux" && syscall.Geteuid() != 0 { 26 t.Skip("Test only available when running as root on linux") 27 } 28 } 29 30 func QemuCompatible(t *testing.T) { 31 // Check if qemu exists 32 bin := "qemu-system-x86_64" 33 if runtime.GOOS == "windows" { 34 bin = "qemu-img" 35 } 36 _, err := exec.Command(bin, "--version").CombinedOutput() 37 if err != nil { 38 t.Skip("Must have Qemu installed for Qemu specific tests to run") 39 } 40 } 41 42 var rktExists bool 43 var rktOnce sync.Once 44 45 func RktCompatible(t *testing.T) { 46 if runtime.GOOS != "linux" || syscall.Geteuid() != 0 { 47 t.Skip("Must be root on Linux to run test") 48 } 49 50 // else see if rkt exists 51 rktOnce.Do(func() { 52 _, err := exec.Command("rkt", "version").CombinedOutput() 53 if err == nil { 54 rktExists = true 55 } 56 }) 57 58 if !rktExists { 59 t.Skip("Must have rkt installed for rkt specific tests to run") 60 } 61 } 62 63 func MountCompatible(t *testing.T) { 64 if runtime.GOOS == "windows" { 65 t.Skip("Windows does not support mount") 66 } 67 68 if syscall.Geteuid() != 0 { 69 t.Skip("Must be root to run test") 70 } 71 }