Skip to content

Commit

Permalink
separate tests
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Okhlopkov <pavel.okhlopkov@flant.com>
  • Loading branch information
Pavel Okhlopkov committed Oct 28, 2024
1 parent 313fc09 commit 9577036
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions pkg/unilogger/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 9577036

Please sign in to comment.