]> Cypherpunks repositories - gostls13.git/commitdiff
testing/slogtest: test nested groups in empty record
authorjunya koyama <arukiidou@yahoo.co.jp>
Sun, 23 Mar 2025 10:04:50 +0000 (10:04 +0000)
committerJonathan Amsterdam <jba@google.com>
Wed, 26 Mar 2025 02:19:09 +0000 (19:19 -0700)
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>
src/testing/slogtest/slogtest.go

index f9e2d900419ab43204471accef09786abc1dafdd..7378b0613d8917c95ff83ab3bdcbde423d7a8e8e 100644 (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"),