Skip to content

Commit

Permalink
tests: get tests building if not yet passing
Browse files Browse the repository at this point in the history
  • Loading branch information
schmichael committed Oct 16, 2018
1 parent 9c5d25e commit f5ea7c6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
8 changes: 5 additions & 3 deletions command/agent/consul/script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}

Expand Down
4 changes: 3 additions & 1 deletion command/agent/consul/unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
}

Expand Down
7 changes: 4 additions & 3 deletions plugins/drivers/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions plugins/drivers/testing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package drivers
import (
"testing"

cstructs "github.com/hashicorp/nomad/client/structs"
"github.com/stretchr/testify/require"
)

Expand All @@ -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)
}

0 comments on commit f5ea7c6

Please sign in to comment.