-
Notifications
You must be signed in to change notification settings - Fork 1
/
levels_test.go
40 lines (35 loc) · 924 Bytes
/
levels_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
package glo
import (
"testing"
)
func TestLevelSnap(t *testing.T) {
if levelSnap(Alert) != Alert {
t.Error("levelSnap equal")
} else if levelSnap(Alert-1) != Critical {
t.Error("levelSnap lesser")
} else if levelSnap(Alert+1) != Alert {
t.Error("levelSnap greater")
}
}
func TestLevelString(t *testing.T) {
for lvl, exp := range levelNames {
got := lvl.String()
if got != exp {
t.Errorf("invalid toString format for Level %d, expected(%s) got(%s)", lvl, exp, got)
}
}
}
func TestLevelOrder(t *testing.T) {
testLevelGreater(t, Emergency, Alert)
testLevelGreater(t, Alert, Critical)
testLevelGreater(t, Critical, Error)
testLevelGreater(t, Error, Warning)
testLevelGreater(t, Warning, Notice)
testLevelGreater(t, Notice, Info)
testLevelGreater(t, Info, Debug)
}
func testLevelGreater(t *testing.T, a, b Level) {
if a <= b {
t.Errorf("%[2]s(%[2]d) is greater than %[1]s(%[1]d)", a, b)
}
}