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 <dmitshur@google.com>
Auto-Submit: Sean Liao <sean@liao.dev>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Sean Liao <sean@liao.dev>
This commit is contained in:
junya koyama 2025-03-23 10:04:50 +00:00 committed by Jonathan Amsterdam
parent 0095b5d098
commit 99d97d7c4f

View File

@ -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"),