chore: 初始提交 Fonu 1.0.2
- 公网反代:Nginx 状态卡片(版本 / 运行状态 / 配置校验 / 端口监听) - 部署设置第一、二梯队(HTTPS 开关、安全头、限流、连接数、仅中国大陆 IP) - 隧道检测兼容 frps v0.68 / v0.71(V2 与旧版端点) - 恢复被清空的 internal/frp/store.go、internal/api/ddns_handler.go、web/src/views/DdnsView.vue
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
package notify
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSendCustomWebhook(t *testing.T) {
|
||||
var body string
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
raw, _ := io.ReadAll(r.Body)
|
||||
body = string(raw)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
cfg := RuntimeConfig{
|
||||
Config: Config{
|
||||
Type: NotifyTypeWebhook,
|
||||
Webhook: WebhookConfig{
|
||||
Provider: WebhookCustom,
|
||||
URL: server.URL,
|
||||
},
|
||||
},
|
||||
}
|
||||
content := FormatAlert("test", "title", "message")
|
||||
if err := SendWebhook(context.Background(), server.Client(), cfg, content); err != nil {
|
||||
t.Fatalf("send custom webhook: %v", err)
|
||||
}
|
||||
if !strings.Contains(body, `"title":"title"`) || !strings.Contains(body, `"message":"message"`) {
|
||||
t.Fatalf("unexpected body: %s", body)
|
||||
}
|
||||
if !strings.Contains(body, `"formatted":`) {
|
||||
t.Fatalf("missing formatted body: %s", body)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSendNtfyUsesTopic(t *testing.T) {
|
||||
var gotPath string
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
gotPath = r.URL.Path
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
cfg := RuntimeConfig{
|
||||
Config: Config{
|
||||
Type: NotifyTypeWebhook,
|
||||
Webhook: WebhookConfig{
|
||||
Provider: WebhookNtfy,
|
||||
Server: server.URL,
|
||||
Topic: "alerts",
|
||||
},
|
||||
},
|
||||
}
|
||||
if err := SendWebhook(context.Background(), server.Client(), cfg, FormatAlert("test", "title", "message")); err != nil {
|
||||
t.Fatalf("send ntfy: %v", err)
|
||||
}
|
||||
if gotPath != "/alerts" {
|
||||
t.Fatalf("expected /alerts got %s", gotPath)
|
||||
}
|
||||
}
|
||||
|
||||
func TestJoinURL(t *testing.T) {
|
||||
got := joinURL("https://ntfy.sh", "topic")
|
||||
if got != "https://ntfy.sh/topic" {
|
||||
t.Fatalf("unexpected url: %s", got)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user