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:
Mike Morris 2019-11-08 17:51:49 -05:00 committed by GitHub
parent 4f18a30f3e
commit 1112c696cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 4 deletions

View File

@ -27,7 +27,7 @@ import (
func TestFoo_bar(t *testing.T) {
// Create a test Consul server
srv1, err := testutil.NewTestServer()
srv1, err := testutil.NewTestServerT(t)
if err != nil {
t.Fatal(err)
}
@ -35,7 +35,7 @@ func TestFoo_bar(t *testing.T) {
// Create a secondary server, passing in configuration
// 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
})
if err != nil {

View File

@ -211,12 +211,20 @@ type TestServer struct {
tmpdir string
}
// NewTestServer is an easy helper method to create a new Consul
// test server with the most basic configuration.
// Deprecated: Use NewTestServerT instead.
func NewTestServer() (*TestServer, error) {
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) {
return NewTestServerConfigT(nil, cb)
}