Skip to content

Commit 863e31e

Browse files
authored
Make TestLogFormat actually asserts (#7822)
1 parent 5f7647e commit 863e31e

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

base/logging_context_test.go

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ func requireLogIs(t testing.TB, s string, f func()) {
2525

2626
config := &ConsoleLoggerConfig{
2727
ColorEnabled: Ptr(false),
28+
FileLoggerConfig: FileLoggerConfig{
29+
Enabled: Ptr(true),
30+
},
2831
}
2932
tempLogger, err := NewConsoleLogger(TestCtx(t), false, config)
3033
require.NoError(t, err)
@@ -39,23 +42,11 @@ func requireLogIs(t testing.TB, s string, f func()) {
3942

4043
f()
4144

42-
var log string
43-
var originalLog string
44-
// Allow time for logs to be printed
45-
retry := func() (shouldRetry bool, err error, value any) {
46-
originalLog = b.String()
47-
if len(originalLog) < timestampLength {
48-
return false, nil, nil
49-
}
50-
log = originalLog[timestampLength:]
51-
if log == s {
52-
return false, nil, nil
53-
}
54-
return true, nil, nil
55-
}
56-
err, _ = RetryLoop(TestCtx(t), "wait for logs", retry, CreateSleeperFunc(10, 100))
57-
58-
require.NoError(t, err, "Console logs did not contain %q, got %q", s, originalLog)
45+
FlushLogBuffers()
46+
originalLog := b.String()
47+
require.GreaterOrEqual(t, len(originalLog), timestampLength, "%q is not a valid log line, needs to contain timestamp", originalLog)
48+
log := originalLog[timestampLength:]
49+
require.Equal(t, s, log)
5950
}
6051

6152
func RequireLogMessage(t testing.TB, ctx context.Context, expectedMessage string, logString string) {

0 commit comments

Comments
 (0)