diff --git a/pkg/unilogger/logger_test.go b/pkg/unilogger/logger_test.go index 45c76167..6f831a04 100644 --- a/pkg/unilogger/logger_test.go +++ b/pkg/unilogger/logger_test.go @@ -36,23 +36,27 @@ func Test_Logger(t *testing.T) { }, }) - logger.Trace(message, slog.String(argKey, argValue)) - logger.Debug(message, slog.String(argKey, argValue)) - logger.Info(message, slog.String(argKey, argValue)) - logger.Warn(message, slog.String(argKey, argValue)) - //test fatal - logger.Log(context.Background(), unilogger.LevelFatal.Level(), message, slog.String(argKey, argValue)) + t.Run("log output without error", func(t *testing.T) { + logger.Trace(message, slog.String(argKey, argValue)) + logger.Debug(message, slog.String(argKey, argValue)) + logger.Info(message, slog.String(argKey, argValue)) + logger.Warn(message, slog.String(argKey, argValue)) + //test fatal + logger.Log(context.Background(), unilogger.LevelFatal.Level(), message, slog.String(argKey, argValue)) - 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"+ - `{"level":"info","msg":"stub msg","source":"unilogger/logger_test.go:41","stub_arg":"arg","time":"2006-01-02T15:04:05Z"}`+"\n"+ - `{"level":"warn","msg":"stub msg","source":"unilogger/logger_test.go:42","stub_arg":"arg","time":"2006-01-02T15:04:05Z"}`+"\n"+ - `{"level":"fatal","msg":"stub msg","source":"unilogger/logger_test.go:44","stub_arg":"arg","time":"2006-01-02T15:04:05Z"}`+"\n") + 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"+ + `{"level":"info","msg":"stub msg","source":"unilogger/logger_test.go:42","stub_arg":"arg","time":"2006-01-02T15:04:05Z"}`+"\n"+ + `{"level":"warn","msg":"stub msg","source":"unilogger/logger_test.go:43","stub_arg":"arg","time":"2006-01-02T15:04:05Z"}`+"\n"+ + `{"level":"fatal","msg":"stub msg","source":"unilogger/logger_test.go:45","stub_arg":"arg","time":"2006-01-02T15:04:05Z"}`+"\n") + }) - buf.Reset() + t.Run("log output with error", func(t *testing.T) { + buf.Reset() - logger.Error(message, slog.String(argKey, argValue)) + logger.Error(message, slog.String(argKey, argValue)) - assert.Contains(t, buf.String(), `{"level":"error","msg":"stub msg","stub_arg":"arg","stacktrace":"`) + assert.Contains(t, buf.String(), `{"level":"error","msg":"stub msg","stub_arg":"arg","stacktrace":"`) + }) } func Test_LoggerFormat(t *testing.T) {