forked from opalmer/logrusutil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_test.go
117 lines (100 loc) · 2.44 KB
/
setup_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
115
116
117
package logrusutil_test
import (
"io/ioutil"
"testing"
"github.com/opalmer/logrusutil"
"github.com/sirupsen/logrus"
)
func TestConfigureRoot_ErrLevelNotProvided_Level(t *testing.T) {
logger := logrus.New()
cfg := logrusutil.NewConfig()
cfg.Level = ""
if logrusutil.ConfigureLogger(logger, cfg) != logrusutil.ErrLevelNotProvided {
t.Error()
}
}
func TestConfigureRoot_ErrLevelNotProvided_HookLevel(t *testing.T) {
logger := logrus.New()
cfg := logrusutil.NewConfig()
cfg.HookLevel = ""
if logrusutil.ConfigureLogger(logger, cfg) != logrusutil.ErrLevelNotProvided {
t.Error()
}
}
func TestConfigureRoot_DisabledLevel(t *testing.T) {
logger := logrus.New()
cfg := logrusutil.NewConfig()
cfg.Level = logrusutil.DisabledLevel
if err := logrusutil.ConfigureLogger(logger, cfg); err != nil {
t.Error(err)
}
if logger.Level != logrus.PanicLevel {
t.Error()
}
if logger.Out != ioutil.Discard {
t.Error()
}
}
func TestConfigureRoot_HookDisabled(t *testing.T) {
logger := logrus.New()
cfg := logrusutil.NewConfig()
cfg.Level = logrusutil.DisabledLevel
cfg.HookLevel = logrusutil.DisabledLevel
if err := logrusutil.ConfigureLogger(logger, cfg); err != nil {
t.Error(err)
}
if logger.Level != logrus.PanicLevel {
t.Error()
}
if logger.Out != ioutil.Discard {
t.Error()
}
}
func TestConfigureRoot_Level_ParseError(t *testing.T) {
logger := logrus.New()
cfg := logrusutil.NewConfig()
cfg.Level = "foobar"
if err := logrusutil.ConfigureLogger(logger, cfg); err == nil {
t.Error()
}
}
func TestConfigureRoot_HookLevel_BadLevel(t *testing.T) {
logger := logrus.New()
cfg := logrusutil.NewConfig()
cfg.HookLevel = "foobar"
if err := logrusutil.ConfigureLogger(logger, cfg); err == nil {
t.Error()
}
}
func TestConfigureRoot_SetLevel(t *testing.T) {
logger := logrus.New()
for _, level := range logrus.AllLevels {
cfg := logrusutil.NewConfig()
cfg.Level = level.String()
if err := logrusutil.ConfigureLogger(logger, cfg); err != nil {
t.Error(err)
}
if logger.Level != level {
t.Errorf("%s != %s", logger.Level, level)
}
}
}
func TestConfigureLogger(t *testing.T) {
logger := logrus.New()
cfg := logrusutil.NewConfig()
cfg.Level = "warning"
cfg.HookLevel = "warning"
for _, hooks := range logger.Hooks {
if len(hooks) != 0 {
t.Error()
}
}
if err := logrusutil.ConfigureLogger(logger, cfg); err != nil {
t.Error(err)
}
for _, hooks := range logger.Hooks {
if len(hooks) != 1 {
t.Error()
}
}
}