mirror of
https://github.com/kemko/nomad.git
synced 2026-01-05 18:05:42 +03:00
tests: use standard library testing.TB
Glint pulled in an updated version of mitchellh/go-testing-interface which broke some existing tests because the update added a Parallel() method to testing.T. This switches to the standard library testing.TB which doesn't have a Parallel() method.
This commit is contained in:
committed by
Isabel Suchanek
parent
0edda116ad
commit
122a4cb844
@@ -34,7 +34,7 @@ import (
|
||||
|
||||
// makeHTTPServer returns a test server whose logs will be written to
|
||||
// the passed writer. If the writer is nil, the logs are written to stderr.
|
||||
func makeHTTPServer(t testing.T, cb func(c *Config)) *TestAgent {
|
||||
func makeHTTPServer(t testing.TB, cb func(c *Config)) *TestAgent {
|
||||
return NewTestAgent(t, t.Name(), cb)
|
||||
}
|
||||
|
||||
|
||||
@@ -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"
|
||||
@@ -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
|
||||
@@ -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,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package state
|
||||
|
||||
import (
|
||||
testing "github.com/mitchellh/go-testing-interface"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/nomad/helper/testlog"
|
||||
"github.com/hashicorp/nomad/helper/uuid"
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/hashicorp/nomad/nomad/structs"
|
||||
)
|
||||
|
||||
func TestStateStore(t testing.T) *StateStore {
|
||||
func TestStateStore(t testing.TB) *StateStore {
|
||||
config := &StateStoreConfig{
|
||||
Logger: testlog.HCLogger(t),
|
||||
Region: "global",
|
||||
@@ -24,14 +24,14 @@ func TestStateStore(t testing.T) *StateStore {
|
||||
return state
|
||||
}
|
||||
|
||||
func TestStateStorePublisher(t testing.T) *StateStoreConfig {
|
||||
func TestStateStorePublisher(t testing.TB) *StateStoreConfig {
|
||||
return &StateStoreConfig{
|
||||
Logger: testlog.HCLogger(t),
|
||||
Region: "global",
|
||||
EnablePublisher: true,
|
||||
}
|
||||
}
|
||||
func TestStateStoreCfg(t testing.T, cfg *StateStoreConfig) *StateStore {
|
||||
func TestStateStoreCfg(t testing.TB, cfg *StateStoreConfig) *StateStore {
|
||||
state, err := NewStateStore(cfg)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
|
||||
@@ -3,9 +3,9 @@ package scheduler
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
testing "github.com/mitchellh/go-testing-interface"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/hashicorp/go-memdb"
|
||||
@@ -41,7 +41,7 @@ func (r *RejectPlan) ReblockEval(*structs.Evaluation) error {
|
||||
// store copy and provides the planner interface. It can be extended for various
|
||||
// testing uses or for invoking the scheduler without side effects.
|
||||
type Harness struct {
|
||||
t testing.T
|
||||
t testing.TB
|
||||
State *state.StateStore
|
||||
|
||||
Planner Planner
|
||||
@@ -59,7 +59,7 @@ type Harness struct {
|
||||
}
|
||||
|
||||
// NewHarness is used to make a new testing harness
|
||||
func NewHarness(t testing.T) *Harness {
|
||||
func NewHarness(t testing.TB) *Harness {
|
||||
state := state.TestStateStore(t)
|
||||
h := &Harness{
|
||||
t: t,
|
||||
@@ -71,7 +71,7 @@ func NewHarness(t testing.T) *Harness {
|
||||
|
||||
// NewHarnessWithState creates a new harness with the given state for testing
|
||||
// purposes.
|
||||
func NewHarnessWithState(t testing.T, state *state.StateStore) *Harness {
|
||||
func NewHarnessWithState(t testing.TB, state *state.StateStore) *Harness {
|
||||
return &Harness{
|
||||
t: t,
|
||||
State: state,
|
||||
@@ -272,7 +272,7 @@ func (h *Harness) Process(factory Factory, eval *structs.Evaluation) error {
|
||||
return sched.Process(eval)
|
||||
}
|
||||
|
||||
func (h *Harness) AssertEvalStatus(t testing.T, state string) {
|
||||
func (h *Harness) AssertEvalStatus(t testing.TB, state string) {
|
||||
require.Len(t, h.Evals, 1)
|
||||
update := h.Evals[0]
|
||||
require.Equal(t, state, update.Status)
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
@@ -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{}
|
||||
@@ -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{
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user