-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathslacklogrus_test.go
47 lines (41 loc) · 1.02 KB
/
slacklogrus_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
package slacklogrus
import (
"os"
"testing"
"github.com/sirupsen/logrus"
)
func TestLevels(t *testing.T) {
logrus.SetLevel(logrus.DebugLevel)
hook := &Hook{
SlackHookURL: os.Getenv("TRAVIS_TEST_SLACK_HOOK_URL"),
Username: "hakaselabs-logrus",
IconEmoji: ":mega:",
WithLevels: logrus.AllLevels,
Channel: "#hakaselabs-dev-chan",
}
logrus.AddHook(hook)
logrus.Debug("logging in Debug Mode")
logrus.Info("Logging in Info Mode")
if len(hook.Levels()) < 1 {
t.Error("Error setting level, level length less than 1")
}
}
func TestSendSlackLog(t *testing.T) {
hook := &Hook{
SlackHookURL: os.Getenv("TRAVIS_TEST_SLACK_HOOK_URL"),
Username: "hakaselabs-logrus",
IconEmoji: ":mega:",
WithLevels: logrus.AllLevels,
Channel: "#hakaselabs-dev-chan",
}
err := hook.Fire(&logrus.Entry{
Data: map[string]interface{}{
"tag": "testing",
},
Logger: &logrus.Logger{},
Message: "Testing Slacklogrus Log",
})
if err != nil {
t.Errorf("Could not fire slacklogrus: %v", err)
}
}