Debian Codegraph @

slogtest/slogtest_test.go

raw symbols SCIP
1 package slogtest_test
2
3 import (
4 "log/slog"
5 "testing"
6
7 "github.com/chainguard-dev/clog"
8 "github.com/chainguard-dev/clog/slogtest"
9 )
10
11 func TestSlogTest(t *testing.T) {
12 ctx := slogtest.Context(t)
13
14 clog.FromContext(ctx).With("foo", "bar").Infof("hello world")
15 clog.FromContext(ctx).With("bar", "baz").Infof("me again")
16 clog.FromContext(ctx).With("baz", true).Infof("okay last one")
17
18 clog.FromContext(ctx).Debug("hello debug")
19 clog.FromContext(ctx).Info("hello info")
20 clog.FromContext(ctx).Warn("hello warn")
21 clog.FromContext(ctx).Error("hello error")
22
23 fn(ctx)
24 }
25
26 // TestSlogTestTContext tests the use of t.Context() in Go 1.24+.
27 func TestSlogTestTContext(t *testing.T) {
28 ctx := t.Context()
29 slog.SetDefault(slog.New(slogtest.TestLogger(t).Handler()))
30
31 clog.FromContext(ctx).With("foo", "bar").Infof("hello world")
32 clog.FromContext(ctx).With("bar", "baz").Infof("me again")
33 clog.FromContext(ctx).With("baz", true).Infof("okay last one")
34
35 clog.FromContext(ctx).Debug("hello debug")
36 clog.FromContext(ctx).Info("hello info")
37 clog.FromContext(ctx).Warn("hello warn")
38 clog.FromContext(ctx).Error("hello error")
39
40 fn(ctx)
41 }