Skip to content

Commit

Permalink
logs_test.go: replaceWithStaticTimestamps: ts may not have nanoseconds
Browse files Browse the repository at this point in the history
  • Loading branch information
maelvls committed Oct 18, 2024
1 parent 6752d49 commit a41b832
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pkg/logs/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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+`)
)
Expand Down Expand Up @@ -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 Warn","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 Info","v":0}`,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
Expand Down

0 comments on commit a41b832

Please sign in to comment.