Skip to content
This repository has been archived by the owner on Oct 27, 2020. It is now read-only.

Commit

Permalink
move coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
GRECO, FRANK committed Oct 3, 2017
1 parent 2151695 commit 5cbb581
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions logging/logging_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package logging

import (
"context"
"testing"

"github.com/northwesternmutual/kanali/config"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"go.uber.org/zap/zaptest/observer"
)

func TestWithContext(t *testing.T) {
logger := WithContext(nil)
assert.Nil(t, logger)

logger = WithContext(context.Background())
assert.Nil(t, logger)

viper.SetDefault(config.FlagProcessLogLevel.GetLong(), "foo")
defer viper.Reset()
Init(nil)
logger = WithContext(nil)
assert.True(t, logger.Core().Enabled(zapcore.InfoLevel))
assert.False(t, logger.Core().Enabled(zapcore.DebugLevel))

viper.SetDefault(config.FlagProcessLogLevel.GetLong(), "Warn")
Init(nil)
logger = WithContext(context.Background())
assert.True(t, logger.Core().Enabled(zapcore.WarnLevel))
assert.False(t, logger.Core().Enabled(zapcore.InfoLevel))

core, obsvr := observer.New(zap.NewAtomicLevelAt(zapcore.InfoLevel))
Init(core)
assert.False(t, logger.Core().Enabled(zapcore.InfoLevel))
assert.False(t, logger.Core().Enabled(zapcore.DebugLevel))

ctx := NewContext(context.Background(), zap.String("foo", "bar"))
logger = WithContext(ctx)
logger.Info("test log")
assert.Equal(t, 1, len(obsvr.All()[obsvr.Len()-1].Context))
assert.Equal(t, "foo", obsvr.All()[obsvr.Len()-1].Context[0].Key)
assert.Equal(t, "bar", obsvr.All()[obsvr.Len()-1].Context[0].String)
}

0 comments on commit 5cbb581

Please sign in to comment.