From dab1cf5da9b6328a01ff5e7613368fb26db52623 Mon Sep 17 00:00:00 2001 From: Rene Zbinden Date: Wed, 23 Dec 2020 16:05:24 +0100 Subject: [PATCH] test: add `SetLevel` test --- flash_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/flash_test.go b/flash_test.go index f99fb41..fcbccf1 100644 --- a/flash_test.go +++ b/flash_test.go @@ -17,6 +17,7 @@ import ( "github.com/stretchr/testify/require" "github.com/tj/assert" "go.uber.org/zap" + "go.uber.org/zap/zapcore" ) // nolint: gochecknoglobals @@ -99,6 +100,12 @@ func TestSetDebugWithStacktrace(t *testing.T) { assert.NotEmpty(t, sink.String(), "no debug message logged") l.Error("error") assert.True(t, sink.containsStackTrace(), "stack trace detected") + sink.Reset() + l.SetDebug(false) + l.Debug("debug") + assert.Empty(t, sink.String()) + l.Error("error") + assert.False(t, sink.containsStackTrace()) } func TestDisable(t *testing.T) { @@ -115,6 +122,17 @@ func TestDisable(t *testing.T) { assert.Empty(t, sink.String(), 0) } +func TestSetLeve(t *testing.T) { + defer sink.Reset() + + l := flash.New(flash.WithSink("memory://")) + l.Debug("debug") + assert.Empty(t, sink.String(), 0) + l.SetLevel(zapcore.DebugLevel) + l.Debug("debug") + assert.NotEmpty(t, sink.String(), 0) +} + func TestWithPrometheus(t *testing.T) { defer sink.Reset()