mirror of
https://github.com/status-im/consul.git
synced 2025-01-09 13:26:07 +00:00
testutil: use TestingTB instead of testing.TB
This commit is contained in:
parent
72e64e9f6f
commit
bb2b5dd871
@ -134,7 +134,7 @@ type ServerConfigCallback func(c *TestServerConfig)
|
|||||||
|
|
||||||
// defaultServerConfig returns a new TestServerConfig struct
|
// defaultServerConfig returns a new TestServerConfig struct
|
||||||
// with all of the listen ports incremented by one.
|
// with all of the listen ports incremented by one.
|
||||||
func defaultServerConfig(t CleanupT) *TestServerConfig {
|
func defaultServerConfig(t TestingTB) *TestServerConfig {
|
||||||
nodeID, err := uuid.GenerateUUID()
|
nodeID, err := uuid.GenerateUUID()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@ -216,11 +216,11 @@ type TestServer struct {
|
|||||||
tmpdir string
|
tmpdir string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTestServerConfig creates a new TestServer, and makes a call to an optional
|
// NewTestServerConfigT creates a new TestServer, and makes a call to an optional
|
||||||
// callback function to modify the configuration. If there is an error
|
// callback function to modify the configuration. If there is an error
|
||||||
// configuring or starting the server, the server will NOT be running when the
|
// configuring or starting the server, the server will NOT be running when the
|
||||||
// function returns (thus you do not need to stop it).
|
// function returns (thus you do not need to stop it).
|
||||||
func NewTestServerConfigT(t testing.TB, cb ServerConfigCallback) (*TestServer, error) {
|
func NewTestServerConfigT(t TestingTB, cb ServerConfigCallback) (*TestServer, error) {
|
||||||
path, err := exec.LookPath("consul")
|
path, err := exec.LookPath("consul")
|
||||||
if err != nil || path == "" {
|
if err != nil || path == "" {
|
||||||
return nil, fmt.Errorf("consul not found on $PATH - download and install " +
|
return nil, fmt.Errorf("consul not found on $PATH - download and install " +
|
||||||
|
@ -10,11 +10,11 @@ import (
|
|||||||
"github.com/hashicorp/go-hclog"
|
"github.com/hashicorp/go-hclog"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Logger(t testing.TB) hclog.InterceptLogger {
|
func Logger(t TestingTB) hclog.InterceptLogger {
|
||||||
return LoggerWithOutput(t, NewLogBuffer(t))
|
return LoggerWithOutput(t, NewLogBuffer(t))
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoggerWithOutput(t testing.TB, output io.Writer) hclog.InterceptLogger {
|
func LoggerWithOutput(t TestingTB, output io.Writer) hclog.InterceptLogger {
|
||||||
return hclog.NewInterceptLogger(&hclog.LoggerOptions{
|
return hclog.NewInterceptLogger(&hclog.LoggerOptions{
|
||||||
Name: t.Name(),
|
Name: t.Name(),
|
||||||
Level: hclog.Trace,
|
Level: hclog.Trace,
|
||||||
@ -30,7 +30,7 @@ var sendTestLogsToStdout = os.Getenv("NOLOGBUFFER") == "1"
|
|||||||
//
|
//
|
||||||
// Set the env var NOLOGBUFFER=1 to disable buffering, resulting in all log
|
// Set the env var NOLOGBUFFER=1 to disable buffering, resulting in all log
|
||||||
// output being written immediately to stdout.
|
// output being written immediately to stdout.
|
||||||
func NewLogBuffer(t CleanupT) io.Writer {
|
func NewLogBuffer(t TestingTB) io.Writer {
|
||||||
if sendTestLogsToStdout {
|
if sendTestLogsToStdout {
|
||||||
return os.Stdout
|
return os.Stdout
|
||||||
}
|
}
|
||||||
@ -45,11 +45,6 @@ func NewLogBuffer(t CleanupT) io.Writer {
|
|||||||
return buf
|
return buf
|
||||||
}
|
}
|
||||||
|
|
||||||
type CleanupT interface {
|
|
||||||
Cleanup(f func())
|
|
||||||
Failed() bool
|
|
||||||
}
|
|
||||||
|
|
||||||
type logBuffer struct {
|
type logBuffer struct {
|
||||||
buf *bytes.Buffer
|
buf *bytes.Buffer
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
|
11
sdk/testutil/types.go
Normal file
11
sdk/testutil/types.go
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package testutil
|
||||||
|
|
||||||
|
// TestingTB is an interface that describes the implementation of the testing object.
|
||||||
|
// Using an interface that describes testing.TB instead of the actual implementation
|
||||||
|
// makes testutil usable in a wider variety of contexts (e.g. use with ginkgo : https://godoc.org/github.com/onsi/ginkgo#GinkgoT)
|
||||||
|
type TestingTB interface {
|
||||||
|
Cleanup(func())
|
||||||
|
Failed() bool
|
||||||
|
Logf(format string, args ...interface{})
|
||||||
|
Name() string
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user