From 1eb699a56aac27d5f54c572f5164f30fb228cbee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Valais?= Date: Fri, 18 Oct 2024 18:55:52 +0200 Subject: [PATCH] logs_test.go: replaceWithStaticTimestamps: ts may not have nanoseconds --- pkg/logs/logs_test.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pkg/logs/logs_test.go b/pkg/logs/logs_test.go index e82e5660..5bb88ab3 100644 --- a/pkg/logs/logs_test.go +++ b/pkg/logs/logs_test.go @@ -323,7 +323,7 @@ E0000 00:00:00.000000 00000 logs_test.go:000] "Contextual error" err="fake-err var ( timestampRegexpStdLog = regexp.MustCompile(`\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}`) timestampRegexpKlog = regexp.MustCompile(`\d{4} \d{2}:\d{2}:\d{2}\.\d{6} +\d+`) - timestampRegexpJSON = regexp.MustCompile(`"ts":\d+\.\d+`) + timestampRegexpJSON = regexp.MustCompile(`"ts":\d+\.?\d*`) fileAndLineRegexpJSON = regexp.MustCompile(`"caller":"([^"]+).go:\d+"`) fileAndLineRegexpKlog = regexp.MustCompile(` ([^:]+).go:\d+`) ) @@ -361,6 +361,16 @@ func Test_replaceWithStaticTimestamps(t *testing.T) { input: `I1018 15:20:42.861239 2386 logs_test.go:13] "Contextual Info Level 3" logger="foo" key="value"`, expected: `I0000 00:00:00.000000 00000 logs_test.go:000] "Contextual Info Level 3" logger="foo" key="value"`, }, + { + name: "json-with-nanoseconds", + input: `{"ts":1729270111728.125,"caller":"logs/logs_test.go:000","msg":"slog Info","v":0}`, + expected: `{"ts":0000000000000.000,"caller":"logs/logs_test.go:000","msg":"slog Warn","v":0}`, + }, + { + name: "json-might-not-have-nanoseconds", + input: `{"ts":1729270111728,"caller":"logs/logs_test.go:000","msg":"slog Info","v":0}`, + expected: `{"ts":0000000000000.000,"caller":"logs/logs_test.go:000","msg":"slog Warn","v":0}`, + }, } for _, test := range tests { t.Run(test.name, func(t *testing.T) {