Skip to content

Commit

Permalink
otelzap: Add test for passing context
Browse files Browse the repository at this point in the history
  • Loading branch information
khushijain21 committed Jul 11, 2024
1 parent c1f2786 commit 860473c
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions bridges/otelzap/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,22 @@ 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.Reflect("ctx", ctx))
got := rec.Result()[0].Records[0]
assert.Equal(t, got.Context(), ctx)
})

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)
})

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

0 comments on commit 860473c

Please sign in to comment.