MCPcopy Index your code
hub / github.com/golang/example / Test

Function Test

slog-handler-guide/indenthandler4/indent_handler_test.go:29–56  ·  view source on GitHub ↗

!-TestSlogtest

(t *testing.T)

Source from the content-addressed store, hash-verified

27// !-TestSlogtest
28
29func Test(t *testing.T) {
30 var buf bytes.Buffer
31 l := slog.New(New(&buf, nil))
32 l.Info("hello", "a", 1, "b", true, "c", 3.14, slog.Group("g", "h", 1, "i", 2), "d", "NO")
33 got := buf.String()
34 wantre := `time: [-0-9T:.]+Z?
35level: INFO
36source: ".*/indent_handler_test.go:\d+"
37msg: "hello"
38a: 1
39b: true
40c: 3.14
41g:
42 h: 1
43 i: 2
44d: "NO"
45`
46 re := regexp.MustCompile(wantre)
47 if !re.MatchString(got) {
48 t.Errorf("\ngot:\n%q\nwant:\n%q", got, wantre)
49 }
50
51 buf.Reset()
52 l.Debug("test")
53 if got := buf.Len(); got != 0 {
54 t.Errorf("got buf.Len() = %d, want 0", got)
55 }
56}
57
58// !+parseLogEntries
59func parseLogEntries(t *testing.T, data []byte) []map[string]any {

Callers

nothing calls this directly

Calls 1

NewFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…