mirror of https://github.com/status-im/consul.git
sdk: add NewTestServerT, deprecate NewTestServer (#6761)
* prevent nil pointer deref from t.Logf usage * enforce non-nil *testing.T in NewTestServerT
This commit is contained in:
parent
4f18a30f3e
commit
1112c696cf
|
@ -27,7 +27,7 @@ import (
|
||||||
|
|
||||||
func TestFoo_bar(t *testing.T) {
|
func TestFoo_bar(t *testing.T) {
|
||||||
// Create a test Consul server
|
// Create a test Consul server
|
||||||
srv1, err := testutil.NewTestServer()
|
srv1, err := testutil.NewTestServerT(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ func TestFoo_bar(t *testing.T) {
|
||||||
|
|
||||||
// Create a secondary server, passing in configuration
|
// Create a secondary server, passing in configuration
|
||||||
// to avoid bootstrapping as we are forming a cluster.
|
// to avoid bootstrapping as we are forming a cluster.
|
||||||
srv2, err := testutil.NewTestServerConfig(t, func(c *testutil.TestServerConfig) {
|
srv2, err := testutil.NewTestServerConfigT(t, func(c *testutil.TestServerConfig) {
|
||||||
c.Bootstrap = false
|
c.Bootstrap = false
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -211,12 +211,20 @@ type TestServer struct {
|
||||||
tmpdir string
|
tmpdir string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTestServer is an easy helper method to create a new Consul
|
// Deprecated: Use NewTestServerT instead.
|
||||||
// test server with the most basic configuration.
|
|
||||||
func NewTestServer() (*TestServer, error) {
|
func NewTestServer() (*TestServer, error) {
|
||||||
return NewTestServerConfigT(nil, nil)
|
return NewTestServerConfigT(nil, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewTestServerT is an easy helper method to create a new Consul
|
||||||
|
// test server with the most basic configuration.
|
||||||
|
func NewTestServerT(t *testing.T) (*TestServer, error) {
|
||||||
|
if t == nil {
|
||||||
|
return nil, errors.New("testutil: a non-nil *testing.T is required")
|
||||||
|
}
|
||||||
|
return NewTestServerConfigT(t, nil)
|
||||||
|
}
|
||||||
|
|
||||||
func NewTestServerConfig(cb ServerConfigCallback) (*TestServer, error) {
|
func NewTestServerConfig(cb ServerConfigCallback) (*TestServer, error) {
|
||||||
return NewTestServerConfigT(nil, cb)
|
return NewTestServerConfigT(nil, cb)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue