github.com/yacovm/fabric@v2.0.0-alpha.0.20191128145320-c5d4087dc723+incompatible/common/flogging/levels_test.go (about) 1 /* 2 Copyright IBM Corp. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package flogging_test 8 9 import ( 10 "testing" 11 12 "github.com/hyperledger/fabric/common/flogging" 13 "github.com/stretchr/testify/assert" 14 "go.uber.org/zap/zapcore" 15 ) 16 17 func TestNameToLevel(t *testing.T) { 18 var tests = []struct { 19 names []string 20 level zapcore.Level 21 }{ 22 {names: []string{"PAYLOAD", "payload"}, level: flogging.PayloadLevel}, 23 {names: []string{"DEBUG", "debug"}, level: zapcore.DebugLevel}, 24 {names: []string{"INFO", "info"}, level: zapcore.InfoLevel}, 25 {names: []string{"WARNING", "warning", "WARN", "warn"}, level: zapcore.WarnLevel}, 26 {names: []string{"ERROR", "error"}, level: zapcore.ErrorLevel}, 27 {names: []string{"DPANIC", "dpanic"}, level: zapcore.DPanicLevel}, 28 {names: []string{"PANIC", "panic"}, level: zapcore.PanicLevel}, 29 {names: []string{"FATAL", "fatal"}, level: zapcore.FatalLevel}, 30 {names: []string{"NOTICE", "notice"}, level: zapcore.InfoLevel}, 31 {names: []string{"CRITICAL", "critical"}, level: zapcore.ErrorLevel}, 32 {names: []string{"unexpected", "invalid"}, level: zapcore.InfoLevel}, 33 } 34 35 for _, tc := range tests { 36 for _, name := range tc.names { 37 t.Run(name, func(t *testing.T) { 38 assert.Equal(t, tc.level, flogging.NameToLevel(name)) 39 }) 40 } 41 } 42 } 43 44 func TestIsValidLevel(t *testing.T) { 45 validNames := []string{ 46 "PAYLOAD", "payload", 47 "DEBUG", "debug", 48 "INFO", "info", 49 "WARNING", "warning", 50 "WARN", "warn", 51 "ERROR", "error", 52 "DPANIC", "dpanic", 53 "PANIC", "panic", 54 "FATAL", "fatal", 55 "NOTICE", "notice", 56 "CRITICAL", "critical", 57 } 58 for _, name := range validNames { 59 t.Run(name, func(t *testing.T) { 60 assert.True(t, flogging.IsValidLevel(name)) 61 }) 62 } 63 64 invalidNames := []string{ 65 "george", "bob", 66 "warnings", "inf", 67 "DISABLED", "disabled", // can only be used programmatically 68 } 69 for _, name := range invalidNames { 70 t.Run(name, func(t *testing.T) { 71 assert.False(t, flogging.IsValidLevel(name)) 72 }) 73 } 74 }