forked from anexia-it/go-logrus-cloudlog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloudlog_hook_test.go
48 lines (39 loc) · 878 Bytes
/
cloudlog_hook_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
package cloudlogrus
import (
"testing"
"github.com/sirupsen/logrus"
)
type MockCloudlogClient struct {
events []interface{}
}
func (client *MockCloudlogClient) PushEvent(e interface{}) error {
client.events = append(client.events, e)
return nil
}
var testLevels = []struct {
level logrus.Level
expected int
}{
{logrus.DebugLevel, 4},
{logrus.InfoLevel, 3},
{logrus.WarnLevel, 2},
{logrus.ErrorLevel, 1},
}
func TestHook(t *testing.T) {
client := MockCloudlogClient{}
hook := NewCustomHook(&client, converterFunc, logrus.InfoLevel)
logrus.AddHook(hook)
logrus.SetLevel(logrus.DebugLevel)
for _, e := range testLevels {
client.events = nil
hook.SetLevel(e.level)
logrus.Debug("")
logrus.Info("")
logrus.Warn("")
logrus.Error("")
l := len(client.events)
if l != e.expected {
t.Errorf("len is %v, expected %v", l, e.expected)
}
}
}