Fix test for non-Linux platforms.
The following tests now check a whitelist for whether or not their driver is present or not, or if the OS is supported or not. * `TestAllocDir_MountSharedAlloc` * `TestClient_Drivers_InWhitelist` (`exec` driver) * `TestClient_Drivers` (`exec` driver) * `TestJavaDriver_Fingerprint` (`java` driver)
This commit is contained in:
parent
710173e9cb
commit
2983bd6fce
|
@ -5,6 +5,7 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/nomad/client/testutil"
|
||||
|
@ -12,6 +13,10 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
osMountSharedDirSupport = map[string]bool{
|
||||
"linux": true,
|
||||
}
|
||||
|
||||
t1 = &structs.Task{
|
||||
Name: "web",
|
||||
Driver: "exec",
|
||||
|
@ -193,7 +198,11 @@ func TestAllocDir_MountSharedAlloc(t *testing.T) {
|
|||
for _, task := range tasks {
|
||||
// Mount and then check that the file exists in the task directory.
|
||||
if err := d.MountSharedDir(task.Name); err != nil {
|
||||
t.Fatalf("MountSharedDir(%v) failed: %v", task.Name, err)
|
||||
if v, ok := osMountSharedDirSupport[runtime.GOOS]; v && ok {
|
||||
t.Fatalf("MountSharedDir(%v) failed: %v", task.Name, err)
|
||||
} else {
|
||||
t.Skipf("MountShareDir(%v) failed, no OS support")
|
||||
}
|
||||
}
|
||||
|
||||
taskDir, ok := d.TaskDirs[task.Name]
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
@ -22,7 +23,13 @@ import (
|
|||
ctestutil "github.com/hashicorp/nomad/client/testutil"
|
||||
)
|
||||
|
||||
var nextPort uint32 = 16000
|
||||
var (
|
||||
nextPort uint32 = 16000
|
||||
|
||||
osExecDriverSupport = map[string]bool{
|
||||
"linux": true,
|
||||
}
|
||||
)
|
||||
|
||||
func getPort() int {
|
||||
return int(atomic.AddUint32(&nextPort, 1))
|
||||
|
@ -225,7 +232,11 @@ func TestClient_Drivers(t *testing.T) {
|
|||
|
||||
node := c.Node()
|
||||
if node.Attributes["driver.exec"] == "" {
|
||||
t.Fatalf("missing exec driver")
|
||||
if v, ok := osExecDriverSupport[runtime.GOOS]; v && ok {
|
||||
t.Fatalf("missing exec driver")
|
||||
} else {
|
||||
t.Skipf("missing exec driver, no OS support")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -242,7 +253,11 @@ func TestClient_Drivers_InWhitelist(t *testing.T) {
|
|||
|
||||
node := c.Node()
|
||||
if node.Attributes["driver.exec"] == "" {
|
||||
t.Fatalf("missing exec driver")
|
||||
if v, ok := osExecDriverSupport[runtime.GOOS]; v && ok {
|
||||
t.Fatalf("missing exec driver")
|
||||
} else {
|
||||
t.Skipf("missing exec driver, no OS support")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
@ -15,6 +16,12 @@ import (
|
|||
ctestutils "github.com/hashicorp/nomad/client/testutil"
|
||||
)
|
||||
|
||||
var (
|
||||
osJavaDriverSupport = map[string]bool{
|
||||
"linux": true,
|
||||
}
|
||||
)
|
||||
|
||||
// javaLocated checks whether java is installed so we can run java stuff.
|
||||
func javaLocated() bool {
|
||||
_, err := exec.Command("java", "-version").CombinedOutput()
|
||||
|
@ -40,7 +47,11 @@ func TestJavaDriver_Fingerprint(t *testing.T) {
|
|||
t.Fatalf("Fingerprinter should detect Java when it is installed")
|
||||
}
|
||||
if node.Attributes["driver.java"] != "1" {
|
||||
t.Fatalf("missing driver")
|
||||
if v, ok := osJavaDriverSupport[runtime.GOOS]; v && ok {
|
||||
t.Fatalf("missing java driver")
|
||||
} else {
|
||||
t.Skipf("missing java driver, no OS support")
|
||||
}
|
||||
}
|
||||
for _, key := range []string{"driver.java.version", "driver.java.runtime", "driver.java.vm"} {
|
||||
if node.Attributes[key] == "" {
|
||||
|
|
Loading…
Reference in New Issue