-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsyslog_test.go
57 lines (46 loc) · 1.76 KB
/
syslog_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
package log
import (
"bytes"
. "gopkg.in/check.v1"
)
type SysLoggerSuite struct {
}
var _ = Suite(&SysLoggerSuite{})
func (s *SysLoggerSuite) TestWriter(c *C) {
debug, info, warning, error := &bytes.Buffer{}, &bytes.Buffer{}, &bytes.Buffer{}, &bytes.Buffer{}
// DEBUG logger should log DEBUG, INFO, WARN and ERROR
l := &sysLogger{SeverityDebug, debug, info, warning, error}
c.Assert(l.Writer(SeverityDebug), Equals, debug)
c.Assert(l.Writer(SeverityInfo), Equals, info)
c.Assert(l.Writer(SeverityWarning), Equals, warning)
c.Assert(l.Writer(SeverityError), Equals, error)
// INFO logger should log INFO, WARN and ERROR
l = &sysLogger{SeverityInfo, debug, info, warning, error}
c.Assert(l.Writer(SeverityDebug), IsNil)
c.Assert(l.Writer(SeverityInfo), Equals, info)
c.Assert(l.Writer(SeverityWarning), Equals, warning)
c.Assert(l.Writer(SeverityError), Equals, error)
// WARN logger should log WARN and ERROR
l = &sysLogger{SeverityWarning, debug, info, warning, error}
c.Assert(l.Writer(SeverityDebug), IsNil)
c.Assert(l.Writer(SeverityInfo), IsNil)
c.Assert(l.Writer(SeverityWarning), Equals, warning)
c.Assert(l.Writer(SeverityError), Equals, error)
// ERROR logger should log only ERROR
l = &sysLogger{SeverityError, debug, info, warning, error}
c.Assert(l.Writer(SeverityDebug), IsNil)
c.Assert(l.Writer(SeverityInfo), IsNil)
c.Assert(l.Writer(SeverityWarning), IsNil)
c.Assert(l.Writer(SeverityError), Equals, error)
}
func (s *SysLoggerSuite) TestNewSysLogger(c *C) {
l, err := NewSysLogger(Config{Syslog, "debug"})
c.Assert(err, IsNil)
c.Assert(l, NotNil)
syslog := l.(*sysLogger)
c.Assert(syslog.sev, Equals, SeverityDebug)
c.Assert(syslog.debugW, NotNil)
c.Assert(syslog.infoW, NotNil)
c.Assert(syslog.warnW, NotNil)
c.Assert(syslog.errorW, NotNil)
}