diff --git a/client/alloc_runner_test.go b/client/alloc_runner_test.go index 73b4da19f..2f3462958 100644 --- a/client/alloc_runner_test.go +++ b/client/alloc_runner_test.go @@ -7,6 +7,8 @@ import ( "github.com/hashicorp/nomad/nomad/mock" "github.com/hashicorp/nomad/nomad/structs" "github.com/hashicorp/nomad/testutil" + + clientTestUtil "github.com/hashicorp/nomad/client/testutil" ) type MockAllocStateUpdater struct { @@ -32,6 +34,7 @@ func testAllocRunner() (*MockAllocStateUpdater, *AllocRunner) { } func TestAllocRunner_SimpleRun(t *testing.T) { + clientTestUtil.ExecCompatible(t) upd, ar := testAllocRunner() go ar.Run() defer ar.Destroy() @@ -48,6 +51,7 @@ func TestAllocRunner_SimpleRun(t *testing.T) { } func TestAllocRunner_Destroy(t *testing.T) { + clientTestUtil.ExecCompatible(t) upd, ar := testAllocRunner() // Ensure task takes some time @@ -79,6 +83,7 @@ func TestAllocRunner_Destroy(t *testing.T) { } func TestAllocRunner_Update(t *testing.T) { + clientTestUtil.ExecCompatible(t) upd, ar := testAllocRunner() // Ensure task takes some time diff --git a/client/client_test.go b/client/client_test.go index cb14030a1..98a36c7f3 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -15,6 +15,8 @@ import ( "github.com/hashicorp/nomad/nomad/mock" "github.com/hashicorp/nomad/nomad/structs" "github.com/hashicorp/nomad/testutil" + + clientTestUtil "github.com/hashicorp/nomad/client/testutil" ) var nextPort uint32 = 16000 @@ -137,6 +139,7 @@ func TestClient_Fingerprint(t *testing.T) { } func TestClient_Drivers(t *testing.T) { + clientTestUtil.ExecCompatible(t) c := testClient(t, nil) defer c.Shutdown() @@ -246,6 +249,7 @@ func TestClient_UpdateAllocStatus(t *testing.T) { } func TestClient_WatchAllocs(t *testing.T) { + clientTestUtil.ExecCompatible(t) s1, _ := testServer(t, nil) defer s1.Shutdown() testutil.WaitForLeader(t, s1.RPC) @@ -314,6 +318,7 @@ func TestClient_WatchAllocs(t *testing.T) { } func TestClient_SaveRestoreState(t *testing.T) { + clientTestUtil.ExecCompatible(t) s1, _ := testServer(t, nil) defer s1.Shutdown() testutil.WaitForLeader(t, s1.RPC) diff --git a/client/task_runner_test.go b/client/task_runner_test.go index 32e8b4782..2756ae02d 100644 --- a/client/task_runner_test.go +++ b/client/task_runner_test.go @@ -11,6 +11,8 @@ import ( "github.com/hashicorp/nomad/nomad/mock" "github.com/hashicorp/nomad/nomad/structs" "github.com/hashicorp/nomad/testutil" + + clientTestUtil "github.com/hashicorp/nomad/client/testutil" ) func testLogger() *log.Logger { @@ -44,6 +46,7 @@ func testTaskRunner() (*MockTaskStateUpdater, *TaskRunner) { } func TestTaskRunner_SimpleRun(t *testing.T) { + clientTestUtil.ExecCompatible(t) upd, tr := testTaskRunner() go tr.Run() defer tr.Destroy() @@ -79,6 +82,7 @@ func TestTaskRunner_SimpleRun(t *testing.T) { } func TestTaskRunner_Destroy(t *testing.T) { + clientTestUtil.ExecCompatible(t) upd, tr := testTaskRunner() // Change command to ensure we run for a bit @@ -113,6 +117,7 @@ func TestTaskRunner_Destroy(t *testing.T) { } func TestTaskRunner_Update(t *testing.T) { + clientTestUtil.ExecCompatible(t) _, tr := testTaskRunner() // Change command to ensure we run for a bit diff --git a/client/testutil/driver_compatible.go b/client/testutil/driver_compatible.go new file mode 100644 index 000000000..2f34508a7 --- /dev/null +++ b/client/testutil/driver_compatible.go @@ -0,0 +1,13 @@ +package testutil + +import ( + "runtime" + "syscall" + "testing" +) + +func ExecCompatible(t *testing.T) { + if runtime.GOOS != "windows" && syscall.Geteuid() != 0 { + t.Skip("Must be root on non-windows environments to run test") + } +}