feat(message_gateway): integrate nikoksr/notify engine and support multi-channel push

This commit is contained in:
ryan
2026-09-02 22:30:59 +08:00
parent 90f3efdd50
commit 7df31befb5
13 changed files with 252 additions and 788 deletions
@@ -11,12 +11,6 @@ import (
)
func TestDingTalkPusher(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{"errcode":0,"errmsg":"ok"}`))
}))
defer server.Close()
pusher, err := GetPusher("dingtalk")
if err != nil {
t.Fatalf("failed to get dingtalk pusher: %v", err)
@@ -27,15 +21,9 @@ func TestDingTalkPusher(t *testing.T) {
t.Errorf("ValidateConfig failed: %v", err)
}
_, err = pusher.Send(context.Background(), Config{
URL: server.URL,
Secret: "test_secret",
}, "", map[string]any{
"title": "Alert",
"content": "Server down",
}, "", nil)
if err != nil {
t.Errorf("Send failed: %v", err)
err = pusher.ValidateConfig(Config{})
if err == nil {
t.Errorf("expected error for empty config, got nil")
}
}
@@ -69,58 +57,36 @@ func TestBarkPusher(t *testing.T) {
}
func TestDiscordPusher(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNoContent)
}))
defer server.Close()
pusher, err := GetPusher("discord")
if err != nil {
t.Fatalf("failed to get discord pusher: %v", err)
}
err = pusher.ValidateConfig(Config{URL: "https://discord.com/api/webhooks/123/abc"})
err = pusher.ValidateConfig(Config{Key: "bot_token_123"})
if err != nil {
t.Errorf("ValidateConfig failed: %v", err)
}
_, err = pusher.Send(context.Background(), Config{
URL: server.URL,
}, "", map[string]any{
"title": "Discord Title",
"content": "Discord Content",
"level": "WARN",
}, "", nil)
if err != nil {
t.Errorf("Send failed: %v", err)
err = pusher.ValidateConfig(Config{})
if err == nil {
t.Errorf("expected error for empty config, got nil")
}
}
func TestSlackPusher(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte("ok"))
}))
defer server.Close()
pusher, err := GetPusher("slack")
if err != nil {
t.Fatalf("failed to get slack pusher: %v", err)
}
err = pusher.ValidateConfig(Config{URL: "https://hooks.slack.com/services/123"})
err = pusher.ValidateConfig(Config{Key: "xoxb-123456"})
if err != nil {
t.Errorf("ValidateConfig failed: %v", err)
}
_, err = pusher.Send(context.Background(), Config{
URL: server.URL,
}, "", map[string]any{
"title": "Slack Title",
"content": "Slack Content",
}, "", nil)
if err != nil {
t.Errorf("Send failed: %v", err)
err = pusher.ValidateConfig(Config{})
if err == nil {
t.Errorf("expected error for empty config, got nil")
}
}
@@ -140,3 +106,20 @@ func TestPushoverPusher(t *testing.T) {
t.Errorf("expected error for empty config, got nil")
}
}
func TestLarkPusher(t *testing.T) {
pusher, err := GetPusher("lark")
if err != nil {
t.Fatalf("failed to get lark pusher: %v", err)
}
err = pusher.ValidateConfig(Config{URL: "https://open.feishu.cn/open-apis/bot/v2/hook/xxx"})
if err != nil {
t.Errorf("ValidateConfig failed: %v", err)
}
err = pusher.ValidateConfig(Config{})
if err == nil {
t.Errorf("expected error for empty config, got nil")
}
}