tests: enable raw_exec driver

This commit is contained in:
Mahmood Ali
2019-08-29 20:13:29 -04:00
parent e14619da45
commit 8b688cc70e
3 changed files with 30 additions and 17 deletions

View File

@@ -32,6 +32,12 @@ func TestMain(m *testing.M) {
}
}
func newEnabledRawExecDriver(t *testing.T) *Driver {
d := NewRawExecDriver(testlog.HCLogger(t)).(*Driver)
d.config.Enabled = true
return d
}
func TestRawExecDriver_SetConfig(t *testing.T) {
t.Parallel()
require := require.New(t)
@@ -73,7 +79,7 @@ func TestRawExecDriver_Fingerprint(t *testing.T) {
fingerprintTest := func(config *Config, expected *drivers.Fingerprint) func(t *testing.T) {
return func(t *testing.T) {
require := require.New(t)
d := NewRawExecDriver(testlog.HCLogger(t)).(*Driver)
d := newEnabledRawExecDriver(t)
harness := dtestutil.NewDriverHarness(t, d)
defer harness.Kill()
@@ -133,7 +139,7 @@ func TestRawExecDriver_StartWait(t *testing.T) {
t.Parallel()
require := require.New(t)
d := NewRawExecDriver(testlog.HCLogger(t))
d := newEnabledRawExecDriver(t)
harness := dtestutil.NewDriverHarness(t, d)
defer harness.Kill()
task := &drivers.TaskConfig{
@@ -175,12 +181,12 @@ func TestRawExecDriver_StartWaitRecoverWaitStop(t *testing.T) {
t.Parallel()
require := require.New(t)
d := NewRawExecDriver(testlog.HCLogger(t))
d := newEnabledRawExecDriver(t)
harness := dtestutil.NewDriverHarness(t, d)
defer harness.Kill()
// Disable cgroups so test works without root
config := &Config{NoCgroups: true}
config := &Config{NoCgroups: true, Enabled: true}
var data []byte
require.NoError(basePlug.MsgPackEncode(&data, config))
bconfig := &basePlug.Config{PluginConfig: data}
@@ -219,7 +225,7 @@ func TestRawExecDriver_StartWaitRecoverWaitStop(t *testing.T) {
originalStatus, err := d.InspectTask(task.ID)
require.NoError(err)
d.(*Driver).tasks.Delete(task.ID)
d.tasks.Delete(task.ID)
wg.Wait()
require.True(waitDone)
@@ -258,7 +264,7 @@ func TestRawExecDriver_Start_Wait_AllocDir(t *testing.T) {
t.Parallel()
require := require.New(t)
d := NewRawExecDriver(testlog.HCLogger(t))
d := newEnabledRawExecDriver(t)
harness := dtestutil.NewDriverHarness(t, d)
defer harness.Kill()
@@ -313,7 +319,7 @@ func TestRawExecDriver_Start_Kill_Wait_Cgroup(t *testing.T) {
require := require.New(t)
pidFile := "pid"
d := NewRawExecDriver(testlog.HCLogger(t))
d := newEnabledRawExecDriver(t)
harness := dtestutil.NewDriverHarness(t, d)
defer harness.Kill()
@@ -403,7 +409,7 @@ func TestRawExecDriver_Exec(t *testing.T) {
t.Parallel()
require := require.New(t)
d := NewRawExecDriver(testlog.HCLogger(t))
d := newEnabledRawExecDriver(t)
harness := dtestutil.NewDriverHarness(t, d)
defer harness.Kill()
@@ -476,8 +482,8 @@ func TestRawExecDriver_Disabled(t *testing.T) {
t.Parallel()
require := require.New(t)
d := NewRawExecDriver(testlog.HCLogger(t))
d.(*Driver).config.Enabled = false
d := newEnabledRawExecDriver(t)
d.config.Enabled = false
harness := dtestutil.NewDriverHarness(t, d)
defer harness.Kill()

View File

@@ -13,7 +13,6 @@ import (
"strings"
"time"
"github.com/hashicorp/nomad/helper/testlog"
"github.com/hashicorp/nomad/helper/testtask"
"github.com/hashicorp/nomad/helper/uuid"
basePlug "github.com/hashicorp/nomad/plugins/base"
@@ -31,7 +30,7 @@ func TestRawExecDriver_User(t *testing.T) {
}
require := require.New(t)
d := NewRawExecDriver(testlog.HCLogger(t))
d := newEnabledRawExecDriver(t)
harness := dtestutil.NewDriverHarness(t, d)
task := &drivers.TaskConfig{
@@ -63,7 +62,7 @@ func TestRawExecDriver_Signal(t *testing.T) {
}
require := require.New(t)
d := NewRawExecDriver(testlog.HCLogger(t))
d := newEnabledRawExecDriver(t)
harness := dtestutil.NewDriverHarness(t, d)
task := &drivers.TaskConfig{
@@ -134,12 +133,12 @@ func TestRawExecDriver_StartWaitStop(t *testing.T) {
t.Parallel()
require := require.New(t)
d := NewRawExecDriver(testlog.HCLogger(t))
d := newEnabledRawExecDriver(t)
harness := dtestutil.NewDriverHarness(t, d)
defer harness.Kill()
// Disable cgroups so test works without root
config := &Config{NoCgroups: true}
config := &Config{NoCgroups: true, Enabled: true}
var data []byte
require.NoError(basePlug.MsgPackEncode(&data, config))
bconfig := &basePlug.Config{PluginConfig: data}
@@ -204,7 +203,7 @@ func TestRawExec_ExecTaskStreaming(t *testing.T) {
}
require := require.New(t)
d := NewRawExecDriver(testlog.HCLogger(t))
d := newEnabledRawExecDriver(t)
harness := dtestutil.NewDriverHarness(t, d)
defer harness.Kill()

View File

@@ -10,7 +10,15 @@ import (
// TestPluginLoader returns a plugin loader populated only with internal plugins
func TestPluginLoader(t testing.T) loader.PluginCatalog {
return TestPluginLoaderWithOptions(t, "", nil, nil)
driverConfigs := []*config.PluginConfig{
{
Name: "raw_exec",
Config: map[string]interface{}{
"enabled": true,
},
},
}
return TestPluginLoaderWithOptions(t, "", nil, driverConfigs)
}
// TestPluginLoaderWithOptions allows configuring the plugin loader fully.