mirror of
https://github.com/pomerium/pomerium.git
synced 2025-07-14 15:28:28 +02:00
check level, add test
This commit is contained in:
parent
ce1dc56f49
commit
c33b4dc5f6
2 changed files with 31 additions and 0 deletions
|
@ -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 {
|
||||
if !c.Enabled(e.Level) {
|
||||
return ce
|
||||
}
|
||||
return ce.AddCore(e, c)
|
||||
}
|
||||
|
||||
|
|
28
internal/autocert/certmagic_logger_test.go
Normal file
28
internal/autocert/certmagic_logger_test.go
Normal 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())
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue