tests: Use zaptest.NewLogger in places we missed
This commit is contained in:
@ -22,7 +22,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap/zaptest"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPurgeFile(t *testing.T) {
|
func TestPurgeFile(t *testing.T) {
|
||||||
@ -40,7 +40,7 @@ func TestPurgeFile(t *testing.T) {
|
|||||||
stop, purgec := make(chan struct{}), make(chan string, 10)
|
stop, purgec := make(chan struct{}), make(chan string, 10)
|
||||||
|
|
||||||
// keep 3 most recent files
|
// keep 3 most recent files
|
||||||
errch := purgeFile(zap.NewExample(), dir, "test", 3, time.Millisecond, stop, purgec, nil)
|
errch := purgeFile(zaptest.NewLogger(t), dir, "test", 3, time.Millisecond, stop, purgec, nil)
|
||||||
select {
|
select {
|
||||||
case f := <-purgec:
|
case f := <-purgec:
|
||||||
t.Errorf("unexpected purge on %q", f)
|
t.Errorf("unexpected purge on %q", f)
|
||||||
@ -107,7 +107,7 @@ func TestPurgeFileHoldingLockFile(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
stop, purgec := make(chan struct{}), make(chan string, 10)
|
stop, purgec := make(chan struct{}), make(chan string, 10)
|
||||||
errch := purgeFile(zap.NewExample(), dir, "test", 3, time.Millisecond, stop, purgec, nil)
|
errch := purgeFile(zaptest.NewLogger(t), dir, "test", 3, time.Millisecond, stop, purgec, nil)
|
||||||
|
|
||||||
for i := 0; i < 5; i++ {
|
for i := 0; i < 5; i++ {
|
||||||
select {
|
select {
|
||||||
|
@ -24,7 +24,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.uber.org/zap"
|
|
||||||
"go.uber.org/zap/zaptest"
|
"go.uber.org/zap/zaptest"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -34,7 +33,7 @@ func createSelfCert(t *testing.T, hosts ...string) (*TLSInfo, error) {
|
|||||||
|
|
||||||
func createSelfCertEx(t *testing.T, host string, additionalUsages ...x509.ExtKeyUsage) (*TLSInfo, error) {
|
func createSelfCertEx(t *testing.T, host string, additionalUsages ...x509.ExtKeyUsage) (*TLSInfo, error) {
|
||||||
d := t.TempDir()
|
d := t.TempDir()
|
||||||
info, err := SelfCert(zap.NewExample(), d, []string{host + ":0"}, 1, additionalUsages...)
|
info, err := SelfCert(zaptest.NewLogger(t), d, []string{host + ":0"}, 1, additionalUsages...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -520,7 +519,7 @@ func TestNewListenerUnixSocket(t *testing.T) {
|
|||||||
// TestNewListenerTLSInfoSelfCert tests that a new certificate accepts connections.
|
// TestNewListenerTLSInfoSelfCert tests that a new certificate accepts connections.
|
||||||
func TestNewListenerTLSInfoSelfCert(t *testing.T) {
|
func TestNewListenerTLSInfoSelfCert(t *testing.T) {
|
||||||
tmpdir := t.TempDir()
|
tmpdir := t.TempDir()
|
||||||
tlsinfo, err := SelfCert(zap.NewExample(), tmpdir, []string{"127.0.0.1"}, 1)
|
tlsinfo, err := SelfCert(zaptest.NewLogger(t), tmpdir, []string{"127.0.0.1"}, 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"go.etcd.io/etcd/client/pkg/v3/logutil"
|
||||||
"go.etcd.io/etcd/client/pkg/v3/transport"
|
"go.etcd.io/etcd/client/pkg/v3/transport"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
@ -111,7 +112,7 @@ func TestNewClientConfig(t *testing.T) {
|
|||||||
|
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
lg, _ := zap.NewProduction()
|
lg, _ := logutil.CreateDefaultZapLogger(zap.InfoLevel)
|
||||||
|
|
||||||
cfg, err := NewClientConfig(&tc.spec, lg)
|
cfg, err := NewClientConfig(&tc.spec, lg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -15,6 +15,7 @@ require (
|
|||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
github.com/inconshreveable/mousetrap v1.0.0 // indirect
|
github.com/inconshreveable/mousetrap v1.0.0 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
|
@ -11,6 +11,7 @@ github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGX
|
|||||||
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
|
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
|
||||||
github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
|
github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
|
||||||
github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
|
github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
|
||||||
|
github.com/coreos/go-systemd/v22 v22.3.2 h1:D9/bQk5vlXQFZ6Kwuu6zaiXJ9oTPe68++AzAJc1DzSI=
|
||||||
github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||||
github.com/creack/pty v1.1.11 h1:07n33Z8lZxZ2qwegKbObQohDhXDQxiMMz1NOUGYlesw=
|
github.com/creack/pty v1.1.11 h1:07n33Z8lZxZ2qwegKbObQohDhXDQxiMMz1NOUGYlesw=
|
||||||
|
@ -23,7 +23,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.uber.org/zap"
|
"go.etcd.io/etcd/client/pkg/v3/logutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGet(t *testing.T) {
|
func TestGet(t *testing.T) {
|
||||||
@ -204,7 +204,7 @@ func TestLog(t *testing.T) {
|
|||||||
logPath := filepath.Join(os.TempDir(), fmt.Sprintf("test-log-%d", time.Now().UnixNano()))
|
logPath := filepath.Join(os.TempDir(), fmt.Sprintf("test-log-%d", time.Now().UnixNano()))
|
||||||
defer os.RemoveAll(logPath)
|
defer os.RemoveAll(logPath)
|
||||||
|
|
||||||
lcfg := zap.NewProductionConfig()
|
lcfg := logutil.DefaultZapLoggerConfig
|
||||||
lcfg.OutputPaths = []string{logPath}
|
lcfg.OutputPaths = []string{logPath}
|
||||||
lcfg.ErrorOutputPaths = []string{logPath}
|
lcfg.ErrorOutputPaths = []string{logPath}
|
||||||
lg, _ := lcfg.Build()
|
lg, _ := lcfg.Build()
|
||||||
@ -285,7 +285,7 @@ func TestLogIfLong(t *testing.T) {
|
|||||||
logPath := filepath.Join(os.TempDir(), fmt.Sprintf("test-log-%d", time.Now().UnixNano()))
|
logPath := filepath.Join(os.TempDir(), fmt.Sprintf("test-log-%d", time.Now().UnixNano()))
|
||||||
defer os.RemoveAll(logPath)
|
defer os.RemoveAll(logPath)
|
||||||
|
|
||||||
lcfg := zap.NewProductionConfig()
|
lcfg := logutil.DefaultZapLoggerConfig
|
||||||
lcfg.OutputPaths = []string{logPath}
|
lcfg.OutputPaths = []string{logPath}
|
||||||
lcfg.ErrorOutputPaths = []string{logPath}
|
lcfg.ErrorOutputPaths = []string{logPath}
|
||||||
lg, _ := lcfg.Build()
|
lg, _ := lcfg.Build()
|
||||||
|
@ -75,7 +75,7 @@ func TestNewRaftLoggerFromZapCore(t *testing.T) {
|
|||||||
buf := bytes.NewBuffer(nil)
|
buf := bytes.NewBuffer(nil)
|
||||||
syncer := zapcore.AddSync(buf)
|
syncer := zapcore.AddSync(buf)
|
||||||
cr := zapcore.NewCore(
|
cr := zapcore.NewCore(
|
||||||
zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()),
|
zapcore.NewJSONEncoder(logutil.DefaultZapLoggerConfig.EncoderConfig),
|
||||||
syncer,
|
syncer,
|
||||||
zap.NewAtomicLevelAt(zap.InfoLevel),
|
zap.NewAtomicLevelAt(zap.InfoLevel),
|
||||||
)
|
)
|
||||||
|
@ -24,6 +24,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"go.etcd.io/etcd/client/pkg/v3/logutil"
|
||||||
"go.etcd.io/etcd/server/v3/embed"
|
"go.etcd.io/etcd/server/v3/embed"
|
||||||
|
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
@ -33,7 +34,7 @@ var lg *zap.Logger
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
var err error
|
var err error
|
||||||
lg, err = zap.NewProduction()
|
lg, err = logutil.CreateDefaultZapLogger(zap.InfoLevel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@ -49,7 +50,11 @@ func main() {
|
|||||||
panic("specify either 'addr' or 'download-ver'")
|
panic("specify either 'addr' or 'download-ver'")
|
||||||
}
|
}
|
||||||
if *debug {
|
if *debug {
|
||||||
lg = zap.NewExample()
|
var err error
|
||||||
|
lg, err = logutil.CreateDefaultZapLogger(zap.DebugLevel)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ep := *addr
|
ep := *addr
|
||||||
|
Reference in New Issue
Block a user