github.com/qichengzx/mattermost-server@v4.5.1-0.20180604164826-2c75247c97d0+incompatible/mlog/stdlog_test.go (about)

     1  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
     2  // See License.txt for license information.
     3  
     4  package mlog
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/assert"
    10  	"go.uber.org/zap/zapcore"
    11  )
    12  
    13  func TestStdLogInterpretZapEntry(t *testing.T) {
    14  	for _, tc := range []struct {
    15  		testname        string
    16  		message         string
    17  		expectedMessage string
    18  		expectedLevel   zapcore.Level
    19  	}{
    20  		{"Debug Basic", "[DEBUG]My message", "My message", zapcore.DebugLevel},
    21  		{"Debug Basic2", "[DEBG]My message", "My message", zapcore.DebugLevel},
    22  		{"Warn Basic", "[WARN]My message", "My message", zapcore.WarnLevel},
    23  		{"Error Basic", "[ERROR]My message", "My message", zapcore.ErrorLevel},
    24  		{"Error Basic2", "[EROR]My message", "My message", zapcore.ErrorLevel},
    25  		{"Error Basic3", "[ERR]My message", "My message", zapcore.ErrorLevel},
    26  		{"Info Basic", "[INFO]My message", "My message", zapcore.InfoLevel},
    27  		{"Unknown level", "[UNKNOWN]My message", "[UNKNOWN]My message", zapcore.PanicLevel},
    28  		{"No level", "My message", "My message", zapcore.PanicLevel},
    29  		{"Empty message", "", "", zapcore.PanicLevel},
    30  		{"Malformed level", "INFO]My message", "INFO]My message", zapcore.PanicLevel},
    31  	} {
    32  		t.Run(tc.testname, func(t *testing.T) {
    33  			inEntry := zapcore.Entry{
    34  				Level:   zapcore.PanicLevel,
    35  				Message: tc.message,
    36  			}
    37  			resultEntry := stdLogInterpretZapEntry(inEntry)
    38  			assert.Equal(t, tc.expectedMessage, resultEntry.Message)
    39  			assert.Equal(t, tc.expectedLevel, resultEntry.Level)
    40  		})
    41  	}
    42  }