From bd5e1346cec00f80763f5ccc2ad456412afbe999 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Paj=C4=85k?= Date: Mon, 7 Jul 2025 20:48:19 +0200 Subject: [PATCH] log/logtest: improve Transform usage in the example (#6938) --- log/logtest/example_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/log/logtest/example_test.go b/log/logtest/example_test.go index 3ff69d460..ae759848d 100644 --- a/log/logtest/example_test.go +++ b/log/logtest/example_test.go @@ -20,20 +20,18 @@ func Example() { // Emit a log record (code under test). l := rec.Logger("Example") - ctx := context.Background() r := log.Record{} r.SetTimestamp(time.Now()) r.SetSeverity(log.SeverityInfo) r.SetBody(log.StringValue("Hello there")) r.AddAttributes(log.String("foo", "bar")) r.AddAttributes(log.Int("n", 1)) - l.Emit(ctx, r) + l.Emit(context.Background(), r) // Verify that the expected and actual log records match. want := logtest.Recording{ logtest.Scope{Name: "Example"}: []logtest.Record{ { - Context: context.Background(), Severity: log.SeverityInfo, Body: log.StringValue("Hello there"), Attributes: []log.KeyValue{ @@ -45,9 +43,11 @@ func Example() { } got := rec.Result() logtest.AssertEqual(t, want, got, - // Ignore Timestamps. - logtest.Transform(func(time.Time) time.Time { - return time.Time{} + logtest.Transform(func(r logtest.Record) logtest.Record { + r = r.Clone() + r.Context = nil // Ignore context. + r.Timestamp = time.Time{} // Ignore timestamp. + return r }), ) // Output: