Skip to content

Commit

Permalink
otelzap: Add test for passing context (#5897)
Browse files Browse the repository at this point in the history
Part of #5191

Pre-work #5279
  • Loading branch information
khushijain21 authored Jul 12, 2024
1 parent bcbd27a commit 202d387
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions bridges/otelzap/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,26 @@ func TestCore(t *testing.T) {

rec.Reset()

// TODO: Add WriteContext test case.
// TODO: Add WithContext test case.
t.Run("Write Context", func(t *testing.T) {
ctx := context.Background()
ctx = context.WithValue(ctx, testEntry, true)
logger.Info(testMessage, zap.Any("ctx", ctx))
got := rec.Result()[0].Records[0]
assert.Equal(t, got.Context(), ctx)
})

rec.Reset()

t.Run("With Context", func(t *testing.T) {
ctx := context.Background()
ctx = context.WithValue(ctx, testEntry, false)
childlogger := logger.With(zap.Reflect("ctx", ctx))
childlogger.Info(testMessage)
got := rec.Result()[0].Records[0]
assert.Equal(t, got.Context(), ctx)
})

rec.Reset()

// test child logger with accumulated fields
t.Run("With", func(t *testing.T) {
Expand Down

0 comments on commit 202d387

Please sign in to comment.