github.com/saferwall/pe@v1.5.2/log/level_test.go (about) 1 package log 2 3 import "testing" 4 5 func TestLevel_String(t *testing.T) { 6 tests := []struct { 7 name string 8 l Level 9 want string 10 }{ 11 { 12 name: "DEBUG", 13 l: LevelDebug, 14 want: "DEBUG", 15 }, 16 { 17 name: "INFO", 18 l: LevelInfo, 19 want: "INFO", 20 }, 21 { 22 name: "WARN", 23 l: LevelWarn, 24 want: "WARN", 25 }, 26 { 27 name: "ERROR", 28 l: LevelError, 29 want: "ERROR", 30 }, 31 { 32 name: "FATAL", 33 l: LevelFatal, 34 want: "FATAL", 35 }, 36 { 37 name: "other", 38 l: 10, 39 want: "", 40 }, 41 } 42 for _, tt := range tests { 43 t.Run(tt.name, func(t *testing.T) { 44 if got := tt.l.String(); got != tt.want { 45 t.Errorf("String() = %v, want %v", got, tt.want) 46 } 47 }) 48 } 49 } 50 51 func TestParseLevel(t *testing.T) { 52 tests := []struct { 53 name string 54 s string 55 want Level 56 }{ 57 { 58 name: "DEBUG", 59 want: LevelDebug, 60 s: "DEBUG", 61 }, 62 { 63 name: "INFO", 64 want: LevelInfo, 65 s: "INFO", 66 }, 67 { 68 name: "WARN", 69 want: LevelWarn, 70 s: "WARN", 71 }, 72 { 73 name: "ERROR", 74 want: LevelError, 75 s: "ERROR", 76 }, 77 { 78 name: "FATAL", 79 want: LevelFatal, 80 s: "FATAL", 81 }, 82 { 83 name: "other", 84 want: LevelInfo, 85 s: "other", 86 }, 87 } 88 for _, tt := range tests { 89 t.Run(tt.name, func(t *testing.T) { 90 if got := ParseLevel(tt.s); got != tt.want { 91 t.Errorf("ParseLevel() = %v, want %v", got, tt.want) 92 } 93 }) 94 } 95 }