Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
khushijain21 committed May 22, 2024
1 parent 84e69be commit 83230bc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions bridges/otelzap/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ func convertField(fields []zapcore.Field) []log.KeyValue {

return enc.kv
}

func convertLevel(level zapcore.Level) log.Severity {
switch level {
case zapcore.DebugLevel:
Expand Down
10 changes: 6 additions & 4 deletions bridges/otelzap/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,24 @@ import (
var (
testMessage = "log message"
loggerName = "name"
testKey = "key"
testValue = "value"
)

func TestCore(t *testing.T) {
rec := logtest.NewRecorder()
zc := NewCore(loggerName, WithLoggerProvider(rec))
logger := zap.New(zc)

logger.Info(testMessage, zap.String("key", "testValue"))
logger.Info(testMessage, zap.String(testKey, testValue))

// TODO (#5580): Not sure why index 1 is populated with results and not 0.
got := rec.Result()[0].Records[0]
assert.Equal(t, testMessage, got.Body().AsString())
assert.Equal(t, log.SeverityInfo, got.Severity())
assert.Equal(t, 1, got.AttributesLen())
got.WalkAttributes(func(kv log.KeyValue) bool {
assert.Equal(t, "key", string(kv.Key))
assert.Equal(t, "testValue", value2Result(kv.Value))
assert.Equal(t, testKey, string(kv.Key))
assert.Equal(t, testValue, value2Result(kv.Value))
return true
})
}
Expand Down

0 comments on commit 83230bc

Please sign in to comment.