From 31c1f4a61136537c5b9ead371772853e772991bb Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Tue, 5 Sep 2023 19:32:49 +0800 Subject: [PATCH] log/slog: use the general regex expression of datetime in TestPanics When I added this test in CL 514135, I missed the timeRE, we should use it to make this test more precise. Change-Id: I486f8e8bbbc3a17166107ef361d242ddf4ea2928 Reviewed-on: https://go-review.googlesource.com/c/go/+/525556 Run-TryBot: Andy Pan Reviewed-by: Cherry Mui Reviewed-by: Jonathan Amsterdam TryBot-Result: Gopher Robot --- src/log/slog/logger_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/log/slog/logger_test.go b/src/log/slog/logger_test.go index 7d0243e415..17bdff2ba5 100644 --- a/src/log/slog/logger_test.go +++ b/src/log/slog/logger_test.go @@ -22,7 +22,7 @@ import ( "time" ) -const timeRE = `\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}(Z|[+-]\d{2}:\d{2})` +const timeRE = `\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{1,9}(Z|[+-]\d{2}:\d{2})` func TestLogTextHandler(t *testing.T) { ctx := context.Background() @@ -633,10 +633,10 @@ func TestPanics(t *testing.T) { in any out string }{ - {(*panicTextAndJsonMarshaler)(nil), `{"time":".*?","level":"INFO","msg":"msg","p":null}`}, - {panicTextAndJsonMarshaler{io.ErrUnexpectedEOF}, `{"time":".*?","level":"INFO","msg":"msg","p":"!PANIC: unexpected EOF"}`}, - {panicTextAndJsonMarshaler{"panicking"}, `{"time":".*?","level":"INFO","msg":"msg","p":"!PANIC: panicking"}`}, - {panicTextAndJsonMarshaler{42}, `{"time":".*?","level":"INFO","msg":"msg","p":"!PANIC: 42"}`}, + {(*panicTextAndJsonMarshaler)(nil), `{"time":"` + timeRE + `","level":"INFO","msg":"msg","p":null}`}, + {panicTextAndJsonMarshaler{io.ErrUnexpectedEOF}, `{"time":"` + timeRE + `","level":"INFO","msg":"msg","p":"!PANIC: unexpected EOF"}`}, + {panicTextAndJsonMarshaler{"panicking"}, `{"time":"` + timeRE + `","level":"INFO","msg":"msg","p":"!PANIC: panicking"}`}, + {panicTextAndJsonMarshaler{42}, `{"time":"` + timeRE + `","level":"INFO","msg":"msg","p":"!PANIC: 42"}`}, } { Info("msg", "p", pt.in) checkLogOutput(t, logBuf.String(), pt.out) -- 2.48.1