Skip to content

Commit f77cfe0

Browse files
author
Matthew Fisher
committed
test(logger): add filehandler tests
1 parent a770a2c commit f77cfe0

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

logger/syslog/filehandler_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package syslog
2+
3+
import (
4+
"testing"
5+
"time"
6+
)
7+
8+
type TestLogger struct {}
9+
10+
func (tl TestLogger) Print(...interface{}) {}
11+
func (tl TestLogger) Printf(format string, v ...interface{}) {}
12+
func (tl TestLogger) Println(...interface{}) {}
13+
14+
func TestNewFileHandler(t *testing.T) {
15+
fh := NewFileHandler("", 1, func (m *Message) bool {return true}, true)
16+
if fh == nil {
17+
t.Errorf("expected filehandler, got nil")
18+
}
19+
}
20+
21+
func TestSetLogger(t *testing.T) {
22+
tl := TestLogger{}
23+
fh := NewFileHandler("", 1, func (m *Message) bool {return true}, true)
24+
fh.SetLogger(tl)
25+
if fh.l != tl {
26+
t.Errorf("expected the logger to be set")
27+
}
28+
}
29+
30+
func TestHandle(t *testing.T) {
31+
fh := NewFileHandler("/tmp/test", 1, func (m *Message) bool {return true}, true)
32+
handle := fh.Handle(&Message{time.Now(), nil, 0, 0, time.Now(), "localhost", "test", "message", "", ""})
33+
if handle == nil {
34+
t.Errorf("expected a handle, got nil")
35+
}
36+
}

0 commit comments

Comments
 (0)