From 5f4f780e16e9d3ade0af9b6b5a0786f2c06814f0 Mon Sep 17 00:00:00 2001 From: mhartenbower Date: Sun, 13 Oct 2019 14:59:54 -0500 Subject: [PATCH] Add noplogger to tests Signed-off-by: mhartenbower --- bridge_test.go | 4 +++- exporter.go | 4 +++- exporter_test.go | 3 ++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/bridge_test.go b/bridge_test.go index e703c37..c8862df 100644 --- a/bridge_test.go +++ b/bridge_test.go @@ -16,6 +16,8 @@ package main import ( "reflect" "testing" + + "github.com/go-kit/kit/log" ) func TestHandlePacket(t *testing.T) { @@ -413,7 +415,7 @@ func TestHandlePacket(t *testing.T) { }, } - for k, l := range []statsDPacketHandler{&StatsDUDPListener{}, &mockStatsDTCPListener{}} { + for k, l := range []statsDPacketHandler{&StatsDUDPListener{nil, nil, log.NewNopLogger()}, &mockStatsDTCPListener{StatsDTCPListener{nil, nil, log.NewNopLogger()}, log.NewNopLogger()}} { events := make(chan Events, 32) l.SetEventHandler(&unbufferedEventHandler{c: events}) for i, scenario := range scenarios { diff --git a/exporter.go b/exporter.go index 70304e8..a66d1c9 100644 --- a/exporter.go +++ b/exporter.go @@ -18,6 +18,7 @@ import ( "fmt" "io" "net" + "os" "strconv" "strings" "time" @@ -581,7 +582,8 @@ func (l *StatsDUnixgramListener) Listen() { if strings.HasSuffix(err.Error(), "use of closed network connection") { return } - panic(err) + level.Error(l.logger).Log(err) + os.Exit(1) } l.handlePacket(buf[:n]) } diff --git a/exporter_test.go b/exporter_test.go index c6e1c26..ffc1d27 100644 --- a/exporter_test.go +++ b/exporter_test.go @@ -493,7 +493,7 @@ func TestInvalidUtf8InDatadogTagValue(t *testing.T) { ueh := &unbufferedEventHandler{c: events} go func() { - for _, l := range []statsDPacketHandler{&StatsDUDPListener{}, &mockStatsDTCPListener{}} { + for _, l := range []statsDPacketHandler{&StatsDUDPListener{nil, nil, log.NewNopLogger()}, &mockStatsDTCPListener{StatsDTCPListener{nil, nil, log.NewNopLogger()}, log.NewNopLogger()}} { l.SetEventHandler(ueh) l.handlePacket([]byte("bar:200|c|#tag:value\nbar:200|c|#tag:\xc3\x28invalid")) } @@ -648,6 +648,7 @@ type statsDPacketHandler interface { type mockStatsDTCPListener struct { StatsDTCPListener + log.Logger } func (ml *mockStatsDTCPListener) handlePacket(packet []byte) {