summaryrefslogtreecommitdiffstats
path: root/mlog/stdlog_test.go
blob: e924b406bff3079bd3e222d1b02a7cfcd90a3878 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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)
		})
	}
}