check level, add test

This commit is contained in:
Caleb Doxsey 2023-07-19 13:48:22 -06:00
parent ce1dc56f49
commit c33b4dc5f6
2 changed files with 31 additions and 0 deletions

View file

@ -23,6 +23,9 @@ func (c certMagicLoggerCore) With(fs []zapcore.Field) zapcore.Core {
} }
func (c certMagicLoggerCore) Check(e zapcore.Entry, ce *zapcore.CheckedEntry) *zapcore.CheckedEntry { func (c certMagicLoggerCore) Check(e zapcore.Entry, ce *zapcore.CheckedEntry) *zapcore.CheckedEntry {
if !c.Enabled(e.Level) {
return ce
}
return ce.AddCore(e, c) return ce.AddCore(e, c)
} }

View file

@ -0,0 +1,28 @@
package autocert
import (
"bytes"
"errors"
"testing"
"github.com/stretchr/testify/assert"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
func TestCertMagicLogger(t *testing.T) {
t.Parallel()
encoder := zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig())
var buf bytes.Buffer
core := zapcore.NewCore(encoder, zapcore.AddSync(&buf), zapcore.DebugLevel)
core = certMagicLoggerCore{core: core}
logger := zap.New(core)
logger.Info("TEST", zap.Error(errors.New("no OCSP server specified in certificate")))
assert.Empty(t, buf.Bytes())
logger.Info("TEST")
assert.NotEmpty(t, buf.Bytes())
}