From: junya koyama Date: Sun, 23 Mar 2025 10:04:50 +0000 (+0000) Subject: testing/slogtest: test nested groups in empty record X-Git-Tag: go1.25rc1~601 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=99d97d7c4f2c2bb0df30f0ca79924754b3b424ec;p=gostls13.git testing/slogtest: test nested groups in empty record Updates #62280 Change-Id: I1c80cb18bb174b47ff156974f72c37baf6b73635 GitHub-Last-Rev: d98b6cd57eb028af8513f583cbef3ce46505b590 GitHub-Pull-Request: golang/go#65597 Reviewed-on: https://go-review.googlesource.com/c/go/+/562635 Reviewed-by: Dmitri Shuralyov Auto-Submit: Sean Liao Reviewed-by: Jonathan Amsterdam LUCI-TryBot-Result: Go LUCI Reviewed-by: Sean Liao --- diff --git a/src/testing/slogtest/slogtest.go b/src/testing/slogtest/slogtest.go index f9e2d90041..7378b0613d 100644 --- a/src/testing/slogtest/slogtest.go +++ b/src/testing/slogtest/slogtest.go @@ -171,6 +171,22 @@ var cases = []testCase{ inGroup("G", missingKey("H")), }, }, + { + name: "nested-empty-group-record", + explanation: withSource("a Handler should not output nested groups if there are no attributes"), + f: func(l *slog.Logger) { + l.With("a", "b").WithGroup("G").With("c", "d").WithGroup("H").WithGroup("I").Info("msg") + }, + checks: []check{ + hasKey(slog.TimeKey), + hasKey(slog.LevelKey), + hasAttr(slog.MessageKey, "msg"), + hasAttr("a", "b"), + inGroup("G", hasAttr("c", "d")), + inGroup("G", missingKey("H")), + inGroup("G", missingKey("I")), + }, + }, { name: "resolve", explanation: withSource("a Handler should call Resolve on attribute values"),