Skip to content

Commit 9577036

Browse files
author
Pavel Okhlopkov
committed
separate tests
Signed-off-by: Pavel Okhlopkov <[email protected]>
1 parent 313fc09 commit 9577036

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

pkg/unilogger/logger_test.go

+17-13
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,27 @@ func Test_Logger(t *testing.T) {
3636
},
3737
})
3838

39-
logger.Trace(message, slog.String(argKey, argValue))
40-
logger.Debug(message, slog.String(argKey, argValue))
41-
logger.Info(message, slog.String(argKey, argValue))
42-
logger.Warn(message, slog.String(argKey, argValue))
43-
//test fatal
44-
logger.Log(context.Background(), unilogger.LevelFatal.Level(), message, slog.String(argKey, argValue))
39+
t.Run("log output without error", func(t *testing.T) {
40+
logger.Trace(message, slog.String(argKey, argValue))
41+
logger.Debug(message, slog.String(argKey, argValue))
42+
logger.Info(message, slog.String(argKey, argValue))
43+
logger.Warn(message, slog.String(argKey, argValue))
44+
//test fatal
45+
logger.Log(context.Background(), unilogger.LevelFatal.Level(), message, slog.String(argKey, argValue))
4546

46-
assert.Equal(t, buf.String(), `{"level":"debug","msg":"stub msg","source":"unilogger/logger_test.go:40","stub_arg":"arg","time":"2006-01-02T15:04:05Z"}`+"\n"+
47-
`{"level":"info","msg":"stub msg","source":"unilogger/logger_test.go:41","stub_arg":"arg","time":"2006-01-02T15:04:05Z"}`+"\n"+
48-
`{"level":"warn","msg":"stub msg","source":"unilogger/logger_test.go:42","stub_arg":"arg","time":"2006-01-02T15:04:05Z"}`+"\n"+
49-
`{"level":"fatal","msg":"stub msg","source":"unilogger/logger_test.go:44","stub_arg":"arg","time":"2006-01-02T15:04:05Z"}`+"\n")
47+
assert.Equal(t, buf.String(), `{"level":"debug","msg":"stub msg","source":"unilogger/logger_test.go:41","stub_arg":"arg","time":"2006-01-02T15:04:05Z"}`+"\n"+
48+
`{"level":"info","msg":"stub msg","source":"unilogger/logger_test.go:42","stub_arg":"arg","time":"2006-01-02T15:04:05Z"}`+"\n"+
49+
`{"level":"warn","msg":"stub msg","source":"unilogger/logger_test.go:43","stub_arg":"arg","time":"2006-01-02T15:04:05Z"}`+"\n"+
50+
`{"level":"fatal","msg":"stub msg","source":"unilogger/logger_test.go:45","stub_arg":"arg","time":"2006-01-02T15:04:05Z"}`+"\n")
51+
})
5052

51-
buf.Reset()
53+
t.Run("log output with error", func(t *testing.T) {
54+
buf.Reset()
5255

53-
logger.Error(message, slog.String(argKey, argValue))
56+
logger.Error(message, slog.String(argKey, argValue))
5457

55-
assert.Contains(t, buf.String(), `{"level":"error","msg":"stub msg","stub_arg":"arg","stacktrace":"`)
58+
assert.Contains(t, buf.String(), `{"level":"error","msg":"stub msg","stub_arg":"arg","stacktrace":"`)
59+
})
5660
}
5761

5862
func Test_LoggerFormat(t *testing.T) {

0 commit comments

Comments
 (0)