master
go 28 lines 526 Bytes
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 package logger
4
5 import (
6 "context"
7 "testing"
8
9 "github.com/stretchr/testify/assert"
10 )
11
12 func TestContextWithLoggerAndLoggerFromContext(t *testing.T) {
13 log := New()
14
15 ctx := ContextWithLogger(nil, log)
16 got, ok := LoggerFromContext(ctx)
17
18 assert.True(t, ok)
19 assert.Same(t, log, got)
20 }
21
22 func TestContextWithLogger_IgnoresNilLogger(t *testing.T) {
23 ctx := ContextWithLogger(context.Background(), nil)
24 got, ok := LoggerFromContext(ctx)
25
26 assert.False(t, ok)
27 assert.Nil(t, got)
28 }