mirror of
https://github.com/kemko/nomad.git
synced 2026-01-04 17:35:43 +03:00
Guard tests
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
13
client/testutil/driver_compatible.go
Normal file
13
client/testutil/driver_compatible.go
Normal 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")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user