Skip to content

Commit

Permalink
fix unit testing (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
wanliqun authored Apr 25, 2024
1 parent f7aac6c commit 685fc0d
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions log/hook_test.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
package log

import (
"os"
"testing"

"github.com/Conflux-Chain/go-conflux-util/alert"
"github.com/sirupsen/logrus"
)

func initTest() {
// Please set the following enviroments before running tests:
// `TEST_DINGTALK_WEBHOOK`: DingTalk webhook;
// `TEST_DINGTALK_SECRET`: DingTalk secret.

func TestMain(m *testing.M) {
webhook := os.Getenv("TEST_DINGTALK_WEBHOOK")
secret := os.Getenv("TEST_DINGTALK_SECRET")

if len(webhook) == 0 || len(secret) == 0 {
return
}

alert.InitDingTalk(&alert.DingTalkConfig{
Enabled: true,
Webhook: "http://test.webhook",
Secret: "test.secret",
Webhook: webhook,
Secret: secret,
}, []string{"log", "hook", "test"})

os.Exit(m.Run())
}

func TestLogrusAddHooks(t *testing.T) {
initTest()

// Add alert hook for logrus fatal/warn/error level
hookLevels := []logrus.Level{logrus.FatalLevel, logrus.WarnLevel, logrus.ErrorLevel}
dingTalkAlertHook := NewDingTalkAlertHook(hookLevels)
Expand Down

0 comments on commit 685fc0d

Please sign in to comment.