-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontext_test.go
More file actions
42 lines (32 loc) · 834 Bytes
/
context_test.go
File metadata and controls
42 lines (32 loc) · 834 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright © Loft Orbital Solutions Inc.
// Use of this source code is governed by a Apache-2.0-style
// license that can be found in the LICENSE file.
package slogx
import (
"context"
"log/slog"
"testing"
"github.com/stretchr/testify/assert"
)
func TestContextWithLogger(t *testing.T) {
t.Parallel()
l := slog.Default()
ctx := ContextWithLogger(context.Background(), l)
al := ctx.Value(ctxKey{})
assert.Equal(t, l, al)
}
func TestFromContext(t *testing.T) {
t.Parallel()
t.Run("logger found", func(t *testing.T) {
t.Parallel()
l := slog.Default()
ctx := context.WithValue(context.Background(), ctxKey{}, l)
al := FromContext(ctx)
assert.Equal(t, l, al)
})
t.Run("logger not found", func(t *testing.T) {
t.Parallel()
al := FromContext(context.Background())
assert.Equal(t, Default, al)
})
}