Skip to content

Commit

Permalink
Migrate zap to ztest
Browse files Browse the repository at this point in the history
Migrate all tests in the main `zap` package to use the internal `ztest`
helpers. This lets the `zaptest` package take dependencies on `zap`.
  • Loading branch information
Akshay Shah authored and akshayjshah committed Oct 31, 2017
1 parent 14cfca0 commit acf104d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions global_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import (
"time"

"go.uber.org/zap/internal/exit"
"go.uber.org/zap/internal/ztest"

"go.uber.org/zap/zapcore"
"go.uber.org/zap/zaptest"
"go.uber.org/zap/zaptest/observer"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -89,7 +89,7 @@ func TestGlobalsConcurrentUse(t *testing.T) {
}()
}

zaptest.Sleep(100 * time.Millisecond)
ztest.Sleep(100 * time.Millisecond)
stop.Toggle()
wg.Wait()
}
Expand Down
8 changes: 4 additions & 4 deletions logger_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (
"testing"
"time"

"go.uber.org/zap/internal/ztest"
"go.uber.org/zap/zapcore"
"go.uber.org/zap/zaptest"
)

type user struct {
Expand All @@ -52,7 +52,7 @@ func withBenchedLogger(b *testing.B, f func(*Logger)) {
logger := New(
zapcore.NewCore(
zapcore.NewJSONEncoder(NewProductionConfig().EncoderConfig),
&zaptest.Discarder{},
&ztest.Discarder{},
DebugLevel,
))
b.ResetTimer()
Expand Down Expand Up @@ -166,7 +166,7 @@ func BenchmarkAddCallerHook(b *testing.B) {
logger := New(
zapcore.NewCore(
zapcore.NewJSONEncoder(NewProductionConfig().EncoderConfig),
&zaptest.Discarder{},
&ztest.Discarder{},
InfoLevel,
),
AddCaller(),
Expand Down Expand Up @@ -200,7 +200,7 @@ func Benchmark100Fields(b *testing.B) {
const batchSize = 50
logger := New(zapcore.NewCore(
zapcore.NewJSONEncoder(NewProductionConfig().EncoderConfig),
&zaptest.Discarder{},
&ztest.Discarder{},
DebugLevel,
))

Expand Down
10 changes: 5 additions & 5 deletions logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import (
"testing"

"go.uber.org/zap/internal/exit"
"go.uber.org/zap/internal/ztest"
"go.uber.org/zap/zapcore"
"go.uber.org/zap/zaptest"
"go.uber.org/zap/zaptest/observer"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -298,11 +298,11 @@ func TestLoggerNames(t *testing.T) {
}

func TestLoggerWriteFailure(t *testing.T) {
errSink := &zaptest.Buffer{}
errSink := &ztest.Buffer{}
logger := New(
zapcore.NewCore(
zapcore.NewJSONEncoder(NewProductionConfig().EncoderConfig),
zapcore.Lock(zapcore.AddSync(zaptest.FailWriter{})),
zapcore.Lock(zapcore.AddSync(ztest.FailWriter{})),
DebugLevel,
),
ErrorOutput(errSink),
Expand All @@ -322,7 +322,7 @@ func TestLoggerSync(t *testing.T) {
}

func TestLoggerSyncFail(t *testing.T) {
noSync := &zaptest.Buffer{}
noSync := &ztest.Buffer{}
err := errors.New("fail")
noSync.SetError(err)
logger := New(zapcore.NewCore(
Expand Down Expand Up @@ -362,7 +362,7 @@ func TestLoggerAddCaller(t *testing.T) {
}

func TestLoggerAddCallerFail(t *testing.T) {
errBuf := &zaptest.Buffer{}
errBuf := &ztest.Buffer{}
withLogger(t, DebugLevel, opts(AddCaller(), ErrorOutput(errBuf)), func(log *Logger, logs *observer.ObservedLogs) {
log.callerSkip = 1e3
log.Info("Failure.")
Expand Down
4 changes: 2 additions & 2 deletions sugar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
"testing"

"go.uber.org/zap/internal/exit"
"go.uber.org/zap/internal/ztest"
"go.uber.org/zap/zapcore"
"go.uber.org/zap/zaptest"
"go.uber.org/zap/zaptest/observer"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -356,7 +356,7 @@ func TestSugarAddCaller(t *testing.T) {
}

func TestSugarAddCallerFail(t *testing.T) {
errBuf := &zaptest.Buffer{}
errBuf := &ztest.Buffer{}
withSugar(t, DebugLevel, opts(AddCaller(), AddCallerSkip(1e3), ErrorOutput(errBuf)), func(log *SugaredLogger, logs *observer.ObservedLogs) {
log.Info("Failure.")
assert.Regexp(
Expand Down

0 comments on commit acf104d

Please sign in to comment.