-
Notifications
You must be signed in to change notification settings - Fork 0
/
levelfilter_test.go
56 lines (49 loc) · 1.79 KB
/
levelfilter_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
package golog
import (
"testing"
"github.com/stretchr/testify/assert"
)
func Test_LevelFilter_NoLevel(t *testing.T) {
for level := LevelMin; level <= LevelMax; level++ {
assert.True(t, AllLevelsActive.IsActive(nil, level), "NoLevel nevel filters")
}
}
func Test_LevelFilterOutAllOther(t *testing.T) {
for activeLevel := LevelMin; activeLevel <= LevelMax; activeLevel++ {
filter := LevelFilterOutAllOther(activeLevel)
for level := LevelMin; level <= LevelMax; level++ {
assert.True(t, filter.IsActive(nil, level) == (level == activeLevel), "only active when activeLevel")
}
}
}
func Test_LevelFilter_SetActive(t *testing.T) {
for activeLevel := LevelMin; activeLevel <= LevelMax; activeLevel++ {
filter := ^LevelFilter(0)
filter.SetActive(activeLevel, true)
for level := LevelMin; level <= LevelMax; level++ {
assert.True(t, filter.IsActive(nil, level) == (level == activeLevel), "only active when activeLevel")
}
filter.SetActive(activeLevel, false)
for level := LevelMin; level <= LevelMax; level++ {
assert.True(t, !filter.IsActive(nil, level), "never active because set active to false")
}
}
}
func Test_LevelFilterOutBelow(t *testing.T) {
for refLevel := LevelMin; refLevel <= LevelMax; refLevel++ {
filter := LevelFilterOutBelow(refLevel)
for level := LevelMin; level <= LevelMax; level++ {
filteredOut := !filter.IsActive(nil, level)
assert.True(t, filteredOut == (level < refLevel), "not active when below refLevel")
}
}
}
func Test_LevelFilterOutAbove(t *testing.T) {
for refLevel := LevelMin; refLevel <= LevelMax; refLevel++ {
filter := LevelFilterOutAbove(refLevel)
for level := LevelMin; level <= LevelMax; level++ {
filteredOut := !filter.IsActive(nil, level)
assert.True(t, filteredOut == (level > refLevel), "not active when above refLevel")
}
}
}