Skip to content

Commit

Permalink
tests: use standard library testing.TB
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahmood Ali committed Jun 7, 2021
1 parent 8c828e8 commit 199a5c5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
7 changes: 3 additions & 4 deletions command/agent/testagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import (
"os"
"path/filepath"
"strings"
"testing"
"time"

testing "github.com/mitchellh/go-testing-interface"

metrics "github.com/armon/go-metrics"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/nomad/api"
Expand All @@ -39,7 +38,7 @@ var TempDir = os.TempDir()
// is removed after shutdown.
type TestAgent struct {
// T is the testing object
T testing.T
T testing.TB

// Name is an optional name of the agent.
Name string
Expand Down Expand Up @@ -92,7 +91,7 @@ type TestAgent struct {
// NewTestAgent returns a started agent with the given name and
// configuration. The caller should call Shutdown() to stop the agent and
// remove temporary directories.
func NewTestAgent(t testing.T, name string, configCallback func(*Config)) *TestAgent {
func NewTestAgent(t testing.TB, name string, configCallback func(*Config)) *TestAgent {
a := &TestAgent{
T: t,
Name: name,
Expand Down
18 changes: 9 additions & 9 deletions testutil/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package testutil
import (
"fmt"
"os"
"testing"
"time"

"github.com/hashicorp/nomad/nomad/structs"
"github.com/kr/pretty"
testing "github.com/mitchellh/go-testing-interface"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -83,7 +83,7 @@ func IsAppVeyor() bool {
type rpcFn func(string, interface{}, interface{}) error

// WaitForLeader blocks until a leader is elected.
func WaitForLeader(t testing.T, rpc rpcFn) {
func WaitForLeader(t testing.TB, rpc rpcFn) {
t.Helper()
WaitForResult(func() (bool, error) {
args := &structs.GenericRequest{}
Expand All @@ -96,7 +96,7 @@ func WaitForLeader(t testing.T, rpc rpcFn) {
}

// WaitForClient blocks until the client can be found
func WaitForClient(t testing.T, rpc rpcFn, nodeID string) {
func WaitForClient(t testing.TB, rpc rpcFn, nodeID string) {
t.Helper()
WaitForResult(func() (bool, error) {
req := structs.NodeSpecificRequest{
Expand All @@ -123,7 +123,7 @@ func WaitForClient(t testing.T, rpc rpcFn, nodeID string) {
//
// Useful for tests that change cluster topology (e.g. kill a node)
// that should wait until cluster is stable.
func WaitForVotingMembers(t testing.T, rpc rpcFn, nPeers int) {
func WaitForVotingMembers(t testing.TB, rpc rpcFn, nPeers int) {
WaitForResult(func() (bool, error) {
args := &structs.GenericRequest{}
args.AllowStale = true
Expand Down Expand Up @@ -152,7 +152,7 @@ func WaitForVotingMembers(t testing.T, rpc rpcFn, nPeers int) {
}

// RegisterJobWithToken registers a job and uses the job's Region and Namespace.
func RegisterJobWithToken(t testing.T, rpc rpcFn, job *structs.Job, token string) {
func RegisterJobWithToken(t testing.TB, rpc rpcFn, job *structs.Job, token string) {
WaitForResult(func() (bool, error) {
args := &structs.JobRegisterRequest{}
args.Job = job
Expand All @@ -169,11 +169,11 @@ func RegisterJobWithToken(t testing.T, rpc rpcFn, job *structs.Job, token string
t.Logf("Job %q registered", job.ID)
}

func RegisterJob(t testing.T, rpc rpcFn, job *structs.Job) {
func RegisterJob(t testing.TB, rpc rpcFn, job *structs.Job) {
RegisterJobWithToken(t, rpc, job, "")
}

func WaitForRunningWithToken(t testing.T, rpc rpcFn, job *structs.Job, token string) []*structs.AllocListStub {
func WaitForRunningWithToken(t testing.TB, rpc rpcFn, job *structs.Job, token string) []*structs.AllocListStub {
RegisterJobWithToken(t, rpc, job, token)

var resp structs.JobAllocationsResponse
Expand Down Expand Up @@ -211,12 +211,12 @@ func WaitForRunningWithToken(t testing.T, rpc rpcFn, job *structs.Job, token str
}

// WaitForRunning runs a job and blocks until all allocs are out of pending.
func WaitForRunning(t testing.T, rpc rpcFn, job *structs.Job) []*structs.AllocListStub {
func WaitForRunning(t testing.TB, rpc rpcFn, job *structs.Job) []*structs.AllocListStub {
return WaitForRunningWithToken(t, rpc, job, "")
}

// WaitForFiles blocks until all the files in the slice are present
func WaitForFiles(t testing.T, files []string) {
func WaitForFiles(t testing.TB, files []string) {
assert := assert.New(t)
WaitForResult(func() (bool, error) {
for _, f := range files {
Expand Down

0 comments on commit 199a5c5

Please sign in to comment.