forked from YoungPioneers/blog4go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
level_test.go
114 lines (87 loc) · 2.7 KB
/
level_test.go
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// Copyright (c) 2015, huangjunwei <huangjunwei@youmi.net>. All rights reserved.
package blog4go
import (
"testing"
)
func TestLevelValidation(t *testing.T) {
if LevelType(-1).valid() {
t.Errorf("Level Validation Failed. level: %d", -1)
}
if !DEBUG.valid() {
t.Error("DEBUG Level Validation Failed.")
}
}
func TestLevelStringFormat(t *testing.T) {
if "DEBUG" != DEBUG.String() {
t.Error("DEBUG Level to wrong string format.")
}
if "TRACE" != TRACE.String() {
t.Error("TRACE Level to wrong string format.")
}
if "INFO" != INFO.String() {
t.Error("INFO Level to wrong string format.")
}
if "WARN" != WARNING.String() {
t.Error("WARN Level to wrong string format.")
}
if "ERROR" != ERROR.String() {
t.Error("ERROR Level to wrong string format.")
}
if "CRITICAL" != CRITICAL.String() {
t.Error("CRITICAL Level to wrong string format.")
}
if " level=\"DEBUG\" " != DEBUG.prefix() {
t.Error("DEBUG Level to wrong prefix string format.")
}
if " level=\"TRACE\" " != TRACE.prefix() {
t.Error("TRACE Level to wrong prefix string format.")
}
if " level=\"INFO\" " != INFO.prefix() {
t.Error("INFO Level to wrong prefix string format.")
}
if " level=\"WARN\" " != WARNING.prefix() {
t.Error("WARN Level to wrong prefix string format.")
}
if " level=\"ERROR\" " != ERROR.prefix() {
t.Error("ERROR Level to wrong prefix string format.")
}
if " level=\"CRITICAL\" " != CRITICAL.prefix() {
t.Error("CRITICAL Level to wrong prefix string format.")
}
if "UNKNOWN" != LevelType(-1).String() {
t.Error("Wrong Level to wrong string format.")
}
initPrefix(true)
if " level=\"\x1b[37mTRACE\x1b[0m\" " != TRACE.prefix() {
t.Error("TRACE Level with color to wrong prefix string format.")
}
if " level=\"\x1b[32mDEBUG\x1b[0m\" " != DEBUG.prefix() {
t.Error("DEBUG Level with color to wrong prefix string format.")
}
if " level=\"\x1b[34mINFO\x1b[0m\" " != INFO.prefix() {
t.Error("INFO Level with color to wrong prefix string format.")
}
if " level=\"\x1b[33mWARN\x1b[0m\" " != WARNING.prefix() {
t.Error("WARN Level with color to wrong prefix string format.")
}
if " level=\"\x1b[31mERROR\x1b[0m\" " != ERROR.prefix() {
t.Error("ERROR Level with color to wrong prefix string format.")
}
if " level=\"\x1b[31mCRITICAL\x1b[0m\" " != CRITICAL.prefix() {
t.Error("CRITICAL Level with color to wrong prefix string format.")
}
}
func TestStringToLevel(t *testing.T) {
str := "debug"
if DEBUG != LevelFromString(str) {
t.Errorf("String to level failed. str: %s", str)
}
str = "something"
if LevelFromString(str).valid() {
t.Errorf("String to level invalid. str: %s", str)
}
str = ""
if LevelFromString(str).valid() {
t.Error("Empty string to level invalid.")
}
}