Skip to content

Commit

Permalink
use newly available zaptest.NewLogger
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanMertz committed Nov 2, 2018
1 parent e2dc66b commit 7b4a4c8
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 37 deletions.
3 changes: 3 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions streamclient/kafkaclient/eventhandlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ package kafkaclient
import (
"testing"

"github.com/stretchr/testify/assert"

"github.com/confluentinc/confluent-kafka-go/kafka"
"github.com/pkg/errors"
"go.uber.org/zap"
"github.com/stretchr/testify/assert"
"go.uber.org/zap/zaptest"
)

func TestHandleError(t *testing.T) {
Expand All @@ -28,7 +27,7 @@ func TestHandleError(t *testing.T) {

err := testErr{errors.New(tt.err.String()), tt.err}
ch := make(chan error, 100)
logger := zap.NewNop()
logger := zaptest.NewLogger(t)

handleError(err, tt.ignores, ch, logger)

Expand Down
3 changes: 0 additions & 3 deletions streamclient/kafkaclient/producer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/blendle/go-streamprocessor/streamutil/testutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
)

func TestIntegrationNewProducer(t *testing.T) {
Expand Down Expand Up @@ -234,8 +233,6 @@ func BenchmarkIntegrationProducer_Messages(b *testing.B) {
testutil.Integration(b)

topic := testutil.Random(b)
logger, err := zap.NewDevelopment()
require.NoError(b, err, logger)

// We use the default (production-like) config in this benchmark, to simulate
// real-world usage as best as possible.
Expand Down
24 changes: 9 additions & 15 deletions streamclient/kafkaclient/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/blendle/go-streamprocessor/streamutil/testutil"
"github.com/confluentinc/confluent-kafka-go/kafka"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
"go.uber.org/zap/zaptest"
)

// TestConsumer returns a new kafka consumer to be used in test cases. It also
Expand Down Expand Up @@ -172,25 +172,22 @@ func TestOffsets(tb testing.TB, message stream.Message) []kafka.TopicPartition {
func TestConsumerConfig(tb testing.TB, topicAndGroup string, options ...streamconfig.Option) []streamconfig.Option {
var allOptions []streamconfig.Option

opts := streamconfig.ConsumerOptions(func(c *streamconfig.Consumer) {
c.Kafka = kafkaconfig.TestConsumer(tb)
c.Kafka.GroupID = topicAndGroup
c.Kafka.Topics = []string{topicAndGroup}
})

if testutil.Verbose(tb) {
logger, err := zap.NewDevelopment()
require.NoError(tb, err)

verbose := streamconfig.ConsumerOptions(func(c *streamconfig.Consumer) {
c.Logger = logger.Named("TestConsumer")
c.Kafka.Debug.CGRP = true
c.Kafka.Debug.Topic = true
})

allOptions = append(allOptions, verbose)
}

opts := streamconfig.ConsumerOptions(func(c *streamconfig.Consumer) {
c.Logger = zaptest.NewLogger(tb).Named("testConsumer")
c.Kafka = kafkaconfig.TestConsumer(tb)
c.Kafka.GroupID = topicAndGroup
c.Kafka.Topics = []string{topicAndGroup}
})

return append(append(allOptions, opts), options...)
}

Expand All @@ -200,11 +197,7 @@ func TestProducerConfig(tb testing.TB, topic string, options ...streamconfig.Opt
var allOptions []streamconfig.Option

if testutil.Verbose(tb) {
logger, err := zap.NewDevelopment()
require.NoError(tb, err)

verbose := streamconfig.ProducerOptions(func(p *streamconfig.Producer) {
p.Logger = logger.Named("TestProducer")
p.Kafka.Debug.CGRP = true
p.Kafka.Debug.Topic = true
})
Expand All @@ -213,6 +206,7 @@ func TestProducerConfig(tb testing.TB, topic string, options ...streamconfig.Opt
}

opts := streamconfig.ProducerOptions(func(p *streamconfig.Producer) {
p.Logger = zaptest.NewLogger(tb).Named("testProducer")
p.Kafka.ID = "testProducer"
p.Kafka.SessionTimeout = 1 * time.Second
p.Kafka.HeartbeatInterval = 150 * time.Millisecond
Expand Down
9 changes: 5 additions & 4 deletions streamconfig/consumer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import (
"github.com/blendle/go-streamprocessor/streamconfig/kafkaconfig"
"github.com/blendle/go-streamprocessor/streamconfig/pubsubconfig"
"github.com/blendle/go-streamprocessor/streamconfig/standardstreamconfig"
"github.com/blendle/go-streamprocessor/streamutil/testutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zapcore"
"go.uber.org/zap/zaptest"
)

func TestConsumer(t *testing.T) {
Expand All @@ -26,9 +27,9 @@ func TestConsumer(t *testing.T) {
Standardstream: standardstreamconfig.Consumer{},

Global: streamconfig.Global{
Logger: testutil.Logger(t),
HandleInterrupt: false,
Name: "",
Logger: zaptest.NewLogger(t, zaptest.Level(zapcore.ErrorLevel)),
HandleInterrupt: false,
Name: "",
AllowEnvironmentBasedConfiguration: false,
},
}
Expand Down
9 changes: 5 additions & 4 deletions streamconfig/producer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import (
"github.com/blendle/go-streamprocessor/streamconfig/kafkaconfig"
"github.com/blendle/go-streamprocessor/streamconfig/pubsubconfig"
"github.com/blendle/go-streamprocessor/streamconfig/standardstreamconfig"
"github.com/blendle/go-streamprocessor/streamutil/testutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zapcore"
"go.uber.org/zap/zaptest"
)

func TestProducer(t *testing.T) {
Expand All @@ -26,9 +27,9 @@ func TestProducer(t *testing.T) {
Standardstream: standardstreamconfig.Producer{},

Global: streamconfig.Global{
Logger: testutil.Logger(t),
HandleInterrupt: false,
Name: "",
Logger: zaptest.NewLogger(t, zaptest.Level(zapcore.ErrorLevel)),
HandleInterrupt: false,
Name: "",
AllowEnvironmentBasedConfiguration: false,
},
}
Expand Down
10 changes: 3 additions & 7 deletions streamconfig/testing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/blendle/go-streamprocessor/streamconfig/kafkaconfig"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
"go.uber.org/zap/zaptest"
)

func TestTestNewConsumer(t *testing.T) {
Expand All @@ -29,9 +29,7 @@ func TestTestNewConsumer_WithoutDefaults(t *testing.T) {
}

func TestTestNewConsumer_WithOptions(t *testing.T) {
logger, err := zap.NewDevelopment()
require.NoError(t, err)

logger := zaptest.NewLogger(t)
c1 := streamconfig.Consumer{Global: streamconfig.Global{Logger: logger}}
c2 := streamconfig.TestNewConsumer(t, false, streamconfig.Logger(logger))

Expand Down Expand Up @@ -81,9 +79,7 @@ func TestTestNewProducer_WithoutDefaults(t *testing.T) {
}

func TestTestNewProducer_WithOptions(t *testing.T) {
logger, err := zap.NewDevelopment()
require.NoError(t, err)

logger := zaptest.NewLogger(t)
p1 := streamconfig.Producer{Global: streamconfig.Global{Logger: logger}}
p2 := streamconfig.TestNewProducer(t, false, streamconfig.Logger(logger))

Expand Down

0 comments on commit 7b4a4c8

Please sign in to comment.