testing/slogtest: test nested groups

Updates #62280
This commit is contained in:
junya koyama 2024-02-08 18:50:12 +09:00
parent b70244ff7a
commit 94c2e3e9b1
No known key found for this signature in database
GPG Key ID: CF96D4804B10B725
1 changed files with 16 additions and 0 deletions

View File

@ -171,6 +171,22 @@ var cases = []testCase{
inGroup("G", missingKey("H")),
},
},
{
name: "with-group-record-nested",
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"),