-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhealth_hook_test.go
44 lines (39 loc) · 1.03 KB
/
health_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
package health
import (
"fmt"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"testing"
)
func TestFire(t *testing.T) {
assert := assert.New(t)
testCases := []struct {
entry *logrus.Entry
warnings uint64
errors uint64
}{
{&logrus.Entry{Level: logrus.PanicLevel}, 0, 1},
{&logrus.Entry{Level: logrus.FatalLevel}, 0, 1},
{&logrus.Entry{Level: logrus.ErrorLevel}, 0, 1},
{&logrus.Entry{Level: logrus.WarnLevel}, 1, 0},
{&logrus.Entry{Level: logrus.InfoLevel}, 0, 0},
}
for _, tc := range testCases {
t.Run(fmt.Sprintf("entry:%v, warnings:%d, errors:%d", tc.entry, tc.warnings, tc.errors), func(t *testing.T) {
hook := NewHealthHook("1.0.0")
hook.Fire(tc.entry)
assert.Equal(tc.warnings, hook.Health.Warnings)
assert.Equal(tc.errors, hook.Health.Errors)
})
}
}
func TestLevels(t *testing.T) {
hook := NewHealthHook("1.0.0")
assert := assert.New(t)
assert.Equal([]logrus.Level{
logrus.PanicLevel,
logrus.FatalLevel,
logrus.ErrorLevel,
logrus.WarnLevel,
}, hook.Levels())
}