Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'internal/log/log_test.go')
-rw-r--r--internal/log/log_test.go45
1 files changed, 6 insertions, 39 deletions
diff --git a/internal/log/log_test.go b/internal/log/log_test.go
index 5be348027..d51f6da3c 100644
--- a/internal/log/log_test.go
+++ b/internal/log/log_test.go
@@ -1,12 +1,9 @@
package log
import (
- "bytes"
"testing"
- "time"
"github.com/sirupsen/logrus"
- "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@@ -21,7 +18,7 @@ func TestConfigure(t *testing.T) {
desc: "json format with info level",
format: "json",
logger: &logrus.Logger{
- Formatter: &utcFormatter{&logrus.JSONFormatter{TimestampFormat: LogTimestampFormatUTC}},
+ Formatter: &logrus.JSONFormatter{TimestampFormat: LogTimestampFormat},
Level: logrus.InfoLevel,
},
},
@@ -29,15 +26,14 @@ func TestConfigure(t *testing.T) {
desc: "text format with info level",
format: "text",
logger: &logrus.Logger{
- Formatter: &utcFormatter{&logrus.TextFormatter{TimestampFormat: LogTimestampFormatUTC}},
+ Formatter: &logrus.TextFormatter{TimestampFormat: LogTimestampFormat},
Level: logrus.InfoLevel,
},
},
{
desc: "empty format with info level",
logger: &logrus.Logger{
- Formatter: &utcFormatter{&logrus.TextFormatter{TimestampFormat: LogTimestampFormatUTC}},
- Level: logrus.InfoLevel,
+ Level: logrus.InfoLevel,
},
},
{
@@ -45,7 +41,7 @@ func TestConfigure(t *testing.T) {
format: "text",
level: "debug",
logger: &logrus.Logger{
- Formatter: &utcFormatter{&logrus.TextFormatter{TimestampFormat: LogTimestampFormatUTC}},
+ Formatter: &logrus.TextFormatter{TimestampFormat: LogTimestampFormat},
Level: logrus.DebugLevel,
},
},
@@ -54,44 +50,15 @@ func TestConfigure(t *testing.T) {
format: "text",
level: "invalid-level",
logger: &logrus.Logger{
- Formatter: &utcFormatter{&logrus.TextFormatter{TimestampFormat: LogTimestampFormatUTC}},
+ Formatter: &logrus.TextFormatter{TimestampFormat: LogTimestampFormat},
Level: logrus.InfoLevel,
},
},
} {
t.Run(tc.desc, func(t *testing.T) {
- loggers := []*logrus.Logger{{Formatter: &logrus.TextFormatter{}}, {Formatter: &logrus.TextFormatter{}}}
+ loggers := []*logrus.Logger{{}, {}}
Configure(loggers, tc.format, tc.level)
require.Equal(t, []*logrus.Logger{tc.logger, tc.logger}, loggers)
-
- now := time.Now()
- nowUTCFormatted := now.UTC().Format(LogTimestampFormatUTC)
-
- message := "this is a logging message."
- var out bytes.Buffer
-
- // both loggers are the same, so no need to test both the same way
- logger := loggers[0]
- logger.Out = &out
- entry := logger.WithTime(now)
-
- switch tc.level {
- case "debug":
- entry.Debug(message)
- case "warn":
- entry.Warn(message)
- case "error":
- entry.Error(message)
- case "", "info":
- entry.Info(message)
- default:
- entry.Info(message)
- }
-
- if tc.format != "" {
- assert.Contains(t, out.String(), nowUTCFormatted)
- }
- assert.Contains(t, out.String(), message)
})
}
}