MCPcopy Index your code
hub / github.com/coder/slog / TestLogger

Function TestLogger

slog_test.go:33–156  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

31var bg = context.Background()
32
33func TestLogger(t *testing.T) {
34 t.Parallel()
35
36 t.Run("basic", func(t *testing.T) {
37 t.Parallel()
38
39 s1 := &fakeSink{}
40 s2 := &fakeSink{}
41 l := slog.Make(s1)
42 l = l.Leveled(slog.LevelError)
43 l = l.AppendSinks(s2)
44
45 l.Info(bg, "wow", slog.Error(io.EOF))
46 l.Error(bg, "meow", slog.Error(io.ErrUnexpectedEOF))
47
48 assert.Equal(t, "syncs", 1, s1.syncs)
49 assert.Len(t, "entries", 1, s1.entries)
50
51 assert.Equal(t, "sinks", s1, s2)
52 })
53
54 t.Run("helper", func(t *testing.T) {
55 t.Parallel()
56
57 s := &fakeSink{}
58 l := slog.Make(s)
59 h := func(ctx context.Context) {
60 slog.Helper()
61 l.Info(ctx, "logging in helper")
62 }
63
64 ctx := slog.With(bg, slog.F(
65 "ctx", 1024),
66 )
67 h(ctx)
68
69 assert.Len(t, "entries", 1, s.entries)
70 assert.Equal(t, "entry", slog.SinkEntry{
71 Time: s.entries[0].Time,
72
73 Level: slog.LevelInfo,
74 Message: "logging in helper",
75
76 File: slogTestFile,
77 Func: "cdr.dev/slog/v3_test.TestLogger.func2",
78 Line: 67,
79
80 Fields: slog.M(
81 slog.F("ctx", 1024),
82 ),
83 }, s.entries[0])
84 })
85
86 t.Run("entry", func(t *testing.T) {
87 t.Parallel()
88
89 s := &fakeSink{}
90 l := slog.Make(s)

Callers

nothing calls this directly

Calls 14

EqualFunction · 0.92
LenFunction · 0.92
LeveledMethod · 0.80
AppendSinksMethod · 0.80
InfoMethod · 0.80
WithMethod · 0.80
NamedMethod · 0.80
SetExitMethod · 0.80
DebugMethod · 0.80
WarnMethod · 0.80
CriticalMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected