summaryrefslogtreecommitdiffstats
path: root/mlog/stdlog_test.go
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2018-04-30 08:18:04 -0700
committerGitHub <noreply@github.com>2018-04-30 08:18:04 -0700
commit9c5815ee41f29e27774d17382d9a4bd10d208545 (patch)
tree698f38053a5f34e337c6750f95b909028a1649dc /mlog/stdlog_test.go
parent2f175001b45fb282600e4a9aee3c8a79fc682821 (diff)
downloadchat-9c5815ee41f29e27774d17382d9a4bd10d208545.tar.gz
chat-9c5815ee41f29e27774d17382d9a4bd10d208545.tar.bz2
chat-9c5815ee41f29e27774d17382d9a4bd10d208545.zip
Add stdlog interpreter. (#8691)
Diffstat (limited to 'mlog/stdlog_test.go')
-rw-r--r--mlog/stdlog_test.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/mlog/stdlog_test.go b/mlog/stdlog_test.go
new file mode 100644
index 000000000..e924b406b
--- /dev/null
+++ b/mlog/stdlog_test.go
@@ -0,0 +1,42 @@
+// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+package mlog
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+ "go.uber.org/zap/zapcore"
+)
+
+func TestStdLogInterpretZapEntry(t *testing.T) {
+ for _, tc := range []struct {
+ testname string
+ message string
+ expectedMessage string
+ expectedLevel zapcore.Level
+ }{
+ {"Debug Basic", "[DEBUG]My message", "My message", zapcore.DebugLevel},
+ {"Debug Basic2", "[DEBG]My message", "My message", zapcore.DebugLevel},
+ {"Warn Basic", "[WARN]My message", "My message", zapcore.WarnLevel},
+ {"Error Basic", "[ERROR]My message", "My message", zapcore.ErrorLevel},
+ {"Error Basic2", "[EROR]My message", "My message", zapcore.ErrorLevel},
+ {"Error Basic3", "[ERR]My message", "My message", zapcore.ErrorLevel},
+ {"Info Basic", "[INFO]My message", "My message", zapcore.InfoLevel},
+ {"Unknown level", "[UNKNOWN]My message", "[UNKNOWN]My message", zapcore.PanicLevel},
+ {"No level", "My message", "My message", zapcore.PanicLevel},
+ {"Empty message", "", "", zapcore.PanicLevel},
+ {"Malformed level", "INFO]My message", "INFO]My message", zapcore.PanicLevel},
+ } {
+ t.Run(tc.testname, func(t *testing.T) {
+ inEntry := zapcore.Entry{
+ Level: zapcore.PanicLevel,
+ Message: tc.message,
+ }
+ resultEntry := stdLogInterpretZapEntry(inEntry)
+ assert.Equal(t, tc.expectedMessage, resultEntry.Message)
+ assert.Equal(t, tc.expectedLevel, resultEntry.Level)
+ })
+ }
+}