mirror of
https://github.com/kemko/nomad.git
synced 2026-01-07 10:55:42 +03:00
tests: get tests building if not yet passing
This commit is contained in:
@@ -34,8 +34,10 @@ func newBlockingScriptExec() *blockingScriptExec {
|
||||
return &blockingScriptExec{running: make(chan struct{})}
|
||||
}
|
||||
|
||||
func (b *blockingScriptExec) Exec(ctx context.Context, _ string, _ []string) ([]byte, int, error) {
|
||||
func (b *blockingScriptExec) Exec(dur time.Duration, _ string, _ []string) ([]byte, int, error) {
|
||||
b.running <- struct{}{}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), dur)
|
||||
defer cancel()
|
||||
cmd := exec.CommandContext(ctx, testtask.Path(), "sleep", "9000h")
|
||||
testtask.SetCmdEnv(cmd)
|
||||
err := cmd.Run()
|
||||
@@ -145,7 +147,7 @@ func TestConsulScript_Exec_Timeout(t *testing.T) {
|
||||
// sleeperExec sleeps for 100ms but returns successfully to allow testing timeout conditions
|
||||
type sleeperExec struct{}
|
||||
|
||||
func (sleeperExec) Exec(context.Context, string, []string) ([]byte, int, error) {
|
||||
func (sleeperExec) Exec(time.Duration, string, []string) ([]byte, int, error) {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
return []byte{}, 0, nil
|
||||
}
|
||||
@@ -185,7 +187,7 @@ type simpleExec struct {
|
||||
err error
|
||||
}
|
||||
|
||||
func (s simpleExec) Exec(context.Context, string, []string) ([]byte, int, error) {
|
||||
func (s simpleExec) Exec(time.Duration, string, []string) ([]byte, int, error) {
|
||||
return []byte(fmt.Sprintf("code=%d err=%v", s.code, s.err)), s.code, s.err
|
||||
}
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ func newMockExec() *mockExec {
|
||||
}
|
||||
}
|
||||
|
||||
func (m *mockExec) Exec(ctx context.Context, cmd string, args []string) ([]byte, int, error) {
|
||||
func (m *mockExec) Exec(dur time.Duration, cmd string, args []string) ([]byte, int, error) {
|
||||
select {
|
||||
case m.execs <- 1:
|
||||
default:
|
||||
@@ -76,6 +76,8 @@ func (m *mockExec) Exec(ctx context.Context, cmd string, args []string) ([]byte,
|
||||
// Default impl is just "ok"
|
||||
return []byte("ok"), 0, nil
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), dur)
|
||||
defer cancel()
|
||||
return m.ExecFunc(ctx, cmd, args)
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
cstructs "github.com/hashicorp/nomad/client/structs"
|
||||
"github.com/hashicorp/nomad/nomad/structs"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/ugorji/go/codec"
|
||||
@@ -118,18 +119,18 @@ func TestBaseDriver_StartTask(t *testing.T) {
|
||||
state := &testDriverState{Pid: 1, Log: "log"}
|
||||
var handle *TaskHandle
|
||||
impl := &MockDriver{
|
||||
StartTaskF: func(c *TaskConfig) (*TaskHandle, error) {
|
||||
StartTaskF: func(c *TaskConfig) (*TaskHandle, *cstructs.DriverNetwork, error) {
|
||||
handle = NewTaskHandle("test")
|
||||
handle.Config = c
|
||||
handle.State = TaskStateRunning
|
||||
handle.SetDriverState(state)
|
||||
return handle, nil
|
||||
return handle, nil, nil
|
||||
},
|
||||
}
|
||||
|
||||
harness := NewDriverHarness(t, impl)
|
||||
defer harness.Kill()
|
||||
resp, err := harness.StartTask(cfg)
|
||||
resp, _, err := harness.StartTask(cfg)
|
||||
require.NoError(err)
|
||||
require.Equal(cfg.ID, resp.Config.ID)
|
||||
require.Equal(handle.State, resp.State)
|
||||
|
||||
@@ -3,6 +3,7 @@ package drivers
|
||||
import (
|
||||
"testing"
|
||||
|
||||
cstructs "github.com/hashicorp/nomad/client/structs"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
@@ -12,13 +13,13 @@ var _ DriverPlugin = (*MockDriver)(nil)
|
||||
func TestDriverHarness(t *testing.T) {
|
||||
handle := &TaskHandle{Config: &TaskConfig{Name: "mock"}}
|
||||
d := &MockDriver{
|
||||
StartTaskF: func(task *TaskConfig) (*TaskHandle, error) {
|
||||
return handle, nil
|
||||
StartTaskF: func(task *TaskConfig) (*TaskHandle, *cstructs.DriverNetwork, error) {
|
||||
return handle, nil, nil
|
||||
},
|
||||
}
|
||||
harness := NewDriverHarness(t, d)
|
||||
defer harness.Kill()
|
||||
actual, err := harness.StartTask(&TaskConfig{})
|
||||
actual, _, err := harness.StartTask(&TaskConfig{})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, handle.Config.Name, actual.Config.Name)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user