-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
driver_compatible.go
67 lines (57 loc) · 1.5 KB
/
driver_compatible.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package testutil
import (
"os/exec"
"runtime"
"syscall"
"testing"
"github.com/hashicorp/nomad/client/fingerprint"
)
// RequireRoot skips tests unless running on a Unix as root.
func RequireRoot(t *testing.T) {
if syscall.Geteuid() != 0 {
t.Skip("Must run as root on Unix")
}
}
// RequireConsul skips tests unless a Consul binary is available on $PATH.
func RequireConsul(t *testing.T) {
_, err := exec.Command("consul", "version").CombinedOutput()
if err != nil {
t.Skipf("Test requires Consul: %v", err)
}
}
func ExecCompatible(t *testing.T) {
if runtime.GOOS != "linux" || syscall.Geteuid() != 0 {
t.Skip("Test only available running as root on linux")
}
CgroupCompatible(t)
}
func JavaCompatible(t *testing.T) {
if runtime.GOOS == "linux" && syscall.Geteuid() != 0 {
t.Skip("Test only available when running as root on linux")
}
}
func QemuCompatible(t *testing.T) {
// Check if qemu exists
bin := "qemu-system-x86_64"
if runtime.GOOS == "windows" {
bin = "qemu-img"
}
_, err := exec.Command(bin, "--version").CombinedOutput()
if err != nil {
t.Skip("Must have Qemu installed for Qemu specific tests to run")
}
}
func CgroupCompatible(t *testing.T) {
mount, err := fingerprint.FindCgroupMountpointDir()
if err != nil || mount == "" {
t.Skipf("Failed to find cgroup mount: %v %v", mount, err)
}
}
func MountCompatible(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("Windows does not support mount")
}
if syscall.Geteuid() != 0 {
t.Skip("Must be root to run test")
}
}