github.com/hhrutter/nomad@v0.6.0-rc2.0.20170723054333-80c4b03f0705/client/testutil/driver_compatible.go (about)

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