Guard tests

This commit is contained in:
Alex Dadgar
2015-09-22 17:10:03 -07:00
parent 06de892626
commit 891d8b8f47
4 changed files with 28 additions and 0 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -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

View File

@@ -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")
}
}