From 7b4a4c8da8756f9457f5e37b5bf96f93f47dbfd9 Mon Sep 17 00:00:00 2001 From: Jean Mertz Date: Wed, 24 Oct 2018 17:30:01 +0200 Subject: [PATCH] use newly available zaptest.NewLogger --- Gopkg.lock | 3 +++ .../kafkaclient/eventhandlers_test.go | 7 +++--- streamclient/kafkaclient/producer_test.go | 3 --- streamclient/kafkaclient/testing.go | 24 +++++++------------ streamconfig/consumer_test.go | 9 +++---- streamconfig/producer_test.go | 9 +++---- streamconfig/testing_test.go | 10 +++----- 7 files changed, 28 insertions(+), 37 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index 06ee22d..ebf35c7 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -83,7 +83,9 @@ "internal/bufferpool", "internal/color", "internal/exit", + "internal/ztest", "zapcore", + "zaptest", ] pruneopts = "" revision = "ff33455a0e382e8a81d14dd7c922020b6b5e7982" @@ -101,6 +103,7 @@ "github.com/stretchr/testify/require", "go.uber.org/zap", "go.uber.org/zap/zapcore", + "go.uber.org/zap/zaptest", ] solver-name = "gps-cdcl" solver-version = 1 diff --git a/streamclient/kafkaclient/eventhandlers_test.go b/streamclient/kafkaclient/eventhandlers_test.go index 2a58554..43fe060 100644 --- a/streamclient/kafkaclient/eventhandlers_test.go +++ b/streamclient/kafkaclient/eventhandlers_test.go @@ -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) { @@ -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) diff --git a/streamclient/kafkaclient/producer_test.go b/streamclient/kafkaclient/producer_test.go index fd415d6..d986e78 100644 --- a/streamclient/kafkaclient/producer_test.go +++ b/streamclient/kafkaclient/producer_test.go @@ -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) { @@ -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. diff --git a/streamclient/kafkaclient/testing.go b/streamclient/kafkaclient/testing.go index a32812d..5cd2def 100644 --- a/streamclient/kafkaclient/testing.go +++ b/streamclient/kafkaclient/testing.go @@ -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 @@ -172,18 +172,8 @@ 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 }) @@ -191,6 +181,13 @@ func TestConsumerConfig(tb testing.TB, topicAndGroup string, options ...streamco 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...) } @@ -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 }) @@ -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 diff --git a/streamconfig/consumer_test.go b/streamconfig/consumer_test.go index e4410ba..275f79b 100644 --- a/streamconfig/consumer_test.go +++ b/streamconfig/consumer_test.go @@ -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) { @@ -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, }, } diff --git a/streamconfig/producer_test.go b/streamconfig/producer_test.go index 661412c..9798d79 100644 --- a/streamconfig/producer_test.go +++ b/streamconfig/producer_test.go @@ -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) { @@ -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, }, } diff --git a/streamconfig/testing_test.go b/streamconfig/testing_test.go index e796afe..80963c0 100644 --- a/streamconfig/testing_test.go +++ b/streamconfig/testing_test.go @@ -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) { @@ -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)) @@ -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))