重构:完成架构一致性整改与生命周期收口
This commit is contained in:
1 parent
55904cc409
commit
9eb6be2875
344 files changed
+15961
-13926
No files matched your search
@@ -86,18 +86,18 @@ func nilLogger() *slog.Logger {
|
||||
|
||||
// newNotifyStoreBare 提供一个独立 store,方便各测试用例自由构造数据。
|
||||
// 预置一个 admin 用户和一个 cookie_id="cid" 的 cookie 记录以满足外键约束。
|
||||
// newNotifyStoreBare 负责newNotifyStoreBare相关处理。
|
||||
// newNotifyStoreBare 封装newNotifyStoreBare业务协调。
|
||||
func newNotifyStoreBare(t *testing.T) (*db.Store, func()) {
|
||||
t.Helper()
|
||||
// d、err 保存d、err,供当前处理流程使用
|
||||
// d、err 用于本次流程后续判断的d、err
|
||||
d, _, err := db.Open(context.Background(), filepath.Join(t.TempDir(), "test.db"))
|
||||
if err != nil {
|
||||
t.Fatalf("Open: %v", err)
|
||||
}
|
||||
// s 保存s,供当前处理流程使用
|
||||
// s 用于本次流程后续判断的s
|
||||
s := db.NewStore(d, db.DialectSQLite)
|
||||
s.Users.Create(context.Background(), "admin", "[email protected]", "pw")
|
||||
// admin 保存admin,供当前处理流程使用
|
||||
// admin 用于本次流程后续判断的admin
|
||||
admin, _ := s.Users.GetByUsername(context.Background(), "admin")
|
||||
s.Cookies.Save(context.Background(), "cid", "unb=123; _m_h5_tk=tk_1;", admin.ID)
|
||||
return s, func() { _ = d.Close() }
|
||||
@@ -106,16 +106,16 @@ func newNotifyStoreBare(t *testing.T) (*db.Store, func()) {
|
||||
// addWebhookChannel 插入一个 webhook 渠道并绑定到 cookieID,返回渠道 ID。
|
||||
func addWebhookChannel(t *testing.T, s *db.Store, cookieID, name, webhookURL string) int64 {
|
||||
t.Helper()
|
||||
// res、err 保存res、err,供当前处理流程使用
|
||||
// res、err 用于本次流程后续判断的res、err
|
||||
res, err := s.DB.ExecContext(context.Background(),
|
||||
`INSERT INTO notification_channels (name,type,config,enabled,user_id) VALUES (?,?,?,1,1)`,
|
||||
name, "webhook", `{"webhook_url":"`+webhookURL+`"}`)
|
||||
if err != nil {
|
||||
t.Fatalf("insert channel: %v", err)
|
||||
}
|
||||
// id 保存标识,供当前处理流程使用
|
||||
// id 用于本次流程后续判断的标识
|
||||
id, _ := res.LastInsertId()
|
||||
if // err 保存err,供当前处理流程使用
|
||||
if // err 用于本次流程后续判断的err
|
||||
_, err := s.DB.ExecContext(context.Background(),
|
||||
`INSERT INTO message_notifications (cookie_id,channel_id,enabled) VALUES (?,?,1)`,
|
||||
cookieID, id); err != nil {
|
||||
@@ -126,7 +126,7 @@ func addWebhookChannel(t *testing.T, s *db.Store, cookieID, name, webhookURL str
|
||||
|
||||
// TestNotifyAccountAlert_NoStore store 为 nil 时安全返回。
|
||||
func TestNotifyAccountAlert_NoStore(t *testing.T) {
|
||||
// n 保存n,供当前处理流程使用
|
||||
// n 用于本次流程后续判断的n
|
||||
n := &Notifier{logger: nilLogger()}
|
||||
// 不应 panic。
|
||||
n.NotifyAccountAlert("cid", "warn", "标题", "正文")
|
||||
@@ -134,25 +134,25 @@ func TestNotifyAccountAlert_NoStore(t *testing.T) {
|
||||
|
||||
// TestNotifyAccountAlert_NoChannels 无绑定渠道时不报错。
|
||||
func TestNotifyAccountAlert_NoChannels(t *testing.T) {
|
||||
// s、cleanup 保存s、cleanup,供当前处理流程使用
|
||||
// s、cleanup 用于本次流程后续判断的s、cleanup
|
||||
s, cleanup := newNotifyStoreBare(t)
|
||||
defer cleanup()
|
||||
// n 保存n,供当前处理流程使用
|
||||
// n 用于本次流程后续判断的n
|
||||
n := New("cid", s, nil)
|
||||
n.NotifyAccountAlert("cid", "warn", "标题", "正文")
|
||||
}
|
||||
|
||||
// TestNotifyAccountAlert_WithChannel 告警通知发送并包含标题与正文。
|
||||
func TestNotifyAccountAlert_WithChannel(t *testing.T) {
|
||||
// s、cleanup 保存s、cleanup,供当前处理流程使用
|
||||
// s、cleanup 用于本次流程后续判断的s、cleanup
|
||||
s, cleanup := newNotifyStoreBare(t)
|
||||
defer cleanup()
|
||||
|
||||
// gotBody 保存got请求体,供当前处理流程使用
|
||||
// gotBody 用于本次流程后续判断的got请求体
|
||||
var gotBody string
|
||||
// srv 保存srv,供当前处理流程使用
|
||||
// srv 用于本次流程后续判断的srv
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
// b 保存b,供当前处理流程使用
|
||||
// b 用于本次流程后续判断的b
|
||||
b, _ := io.ReadAll(r.Body)
|
||||
gotBody = string(b)
|
||||
w.WriteHeader(200)
|
||||
@@ -160,7 +160,7 @@ func TestNotifyAccountAlert_WithChannel(t *testing.T) {
|
||||
defer srv.Close()
|
||||
|
||||
addWebhookChannel(t, s, "cid", "告警渠道", srv.URL)
|
||||
// n 保存n,供当前处理流程使用
|
||||
// n 用于本次流程后续判断的n
|
||||
n := New("cid", s, nil)
|
||||
n.NotifyAccountAlert("cid", "critical", "Token失效", "请重新登录")
|
||||
|
||||
@@ -172,41 +172,41 @@ func TestNotifyAccountAlert_WithChannel(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestNotifyEventUsesPersistentOutboxWhenStarted 负责TestNotifyEventUsesPersistentOutboxWhenStarted相关处理。
|
||||
// TestNotifyEventUsesPersistentOutboxWhenStarted 封装TestNotifyEventUsesPersistentOutboxWhenStarted业务协调。
|
||||
func TestNotifyEventUsesPersistentOutboxWhenStarted(t *testing.T) {
|
||||
// s、cleanup 保存s、cleanup,供当前处理流程使用
|
||||
// s、cleanup 用于本次流程后续判断的s、cleanup
|
||||
s, cleanup := newNotifyStoreBare(t)
|
||||
defer cleanup()
|
||||
// calls 保存calls,供当前处理流程使用
|
||||
// calls 用于本次流程后续判断的calls
|
||||
var calls int32
|
||||
// srv 保存srv,供当前处理流程使用
|
||||
// srv 用于本次流程后续判断的srv
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
atomic.AddInt32(&calls, 1)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}))
|
||||
defer srv.Close()
|
||||
addWebhookChannel(t, s, "cid", "outbox", srv.URL)
|
||||
// n 保存n,供当前处理流程使用
|
||||
// n 用于本次流程后续判断的n
|
||||
n := New("cid", s, nilLogger())
|
||||
// 标记异步模式但不启动循环,精确验证调用返回时尚未发生外部网络请求。
|
||||
n.started.Store(true)
|
||||
n.NotifyAccountAlert("cid", "warn", "持久化通知", "正文")
|
||||
if // got 保存got,供当前处理流程使用
|
||||
if // got 用于本次流程后续判断的got
|
||||
got := atomic.LoadInt32(&calls); got != 0 {
|
||||
t.Fatalf("business call performed synchronous network I/O: %d", got)
|
||||
}
|
||||
// queued 保存queued,供当前处理流程使用
|
||||
// queued 用于本次流程后续判断的queued
|
||||
var queued int
|
||||
if // err 保存err,供当前处理流程使用
|
||||
if // err 用于本次流程后续判断的err
|
||||
err := s.DB.QueryRow(`SELECT COUNT(*) FROM notification_outbox WHERE status='pending'`).Scan(&queued); err != nil || queued != 1 {
|
||||
t.Fatalf("queued=%d err=%v", queued, err)
|
||||
}
|
||||
n.drainOutbox(context.Background())
|
||||
if // got 保存got,供当前处理流程使用
|
||||
if // got 用于本次流程后续判断的got
|
||||
got := atomic.LoadInt32(&calls); got != 1 {
|
||||
t.Fatalf("outbox delivery calls=%d", got)
|
||||
}
|
||||
if // err 保存err,供当前处理流程使用
|
||||
if // err 用于本次流程后续判断的err
|
||||
err := s.DB.QueryRow(`SELECT COUNT(*) FROM notification_outbox`).Scan(&queued); err != nil || queued != 0 {
|
||||
t.Fatalf("remaining=%d err=%v", queued, err)
|
||||
}
|
||||
@@ -248,7 +248,7 @@ func TestDrainOutbox_SendSuccessCompletionFailureQuarantines(t *testing.T) {
|
||||
|
||||
// TestNotifyAccountAlert_LevelLabels 覆盖 levelLabel 各分支。
|
||||
func TestNotifyAccountAlert_LevelLabels(t *testing.T) {
|
||||
// cases 保存cases,供当前处理流程使用
|
||||
// cases 用于本次流程后续判断的cases
|
||||
cases := map[string]string{
|
||||
"critical": "严重",
|
||||
"warn": "警告",
|
||||
@@ -257,7 +257,7 @@ func TestNotifyAccountAlert_LevelLabels(t *testing.T) {
|
||||
}
|
||||
// level、want 表示当前遍历过程中的level、want
|
||||
for level, want := range cases {
|
||||
if // got 保存got,供当前处理流程使用
|
||||
if // got 用于本次流程后续判断的got
|
||||
got := levelLabel(level); got != want {
|
||||
t.Errorf("levelLabel(%q)=%q want %q", level, got, want)
|
||||
}
|
||||
@@ -266,26 +266,26 @@ func TestNotifyAccountAlert_LevelLabels(t *testing.T) {
|
||||
|
||||
// TestSendToChannel 直接发送到指定渠道。
|
||||
func TestSendToChannel(t *testing.T) {
|
||||
// s、cleanup 保存s、cleanup,供当前处理流程使用
|
||||
// s、cleanup 用于本次流程后续判断的s、cleanup
|
||||
s, cleanup := newNotifyStoreBare(t)
|
||||
defer cleanup()
|
||||
|
||||
// gotBody 保存got请求体,供当前处理流程使用
|
||||
// gotBody 用于本次流程后续判断的got请求体
|
||||
var gotBody string
|
||||
// srv 保存srv,供当前处理流程使用
|
||||
// srv 用于本次流程后续判断的srv
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
// b 保存b,供当前处理流程使用
|
||||
// b 用于本次流程后续判断的b
|
||||
b, _ := io.ReadAll(r.Body)
|
||||
gotBody = string(b)
|
||||
w.WriteHeader(200)
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
// chID 保存chID,供当前处理流程使用
|
||||
// chID 用于本次流程后续判断的chID
|
||||
chID := addWebhookChannel(t, s, "cid", "直发渠道", srv.URL)
|
||||
// n 保存n,供当前处理流程使用
|
||||
// n 用于本次流程后续判断的n
|
||||
n := New("cid", s, nil)
|
||||
if // err 保存err,供当前处理流程使用
|
||||
if // err 用于本次流程后续判断的err
|
||||
err := n.SendToChannel(chID, "直发测试"); err != nil {
|
||||
t.Fatalf("SendToChannel: %v", err)
|
||||
}
|
||||
@@ -298,15 +298,15 @@ func TestSendToChannel(t *testing.T) {
|
||||
func TestSendToChannel_Errors(t *testing.T) {
|
||||
// store 为 nil。
|
||||
n := &Notifier{logger: nilLogger()}
|
||||
if // err 保存err,供当前处理流程使用
|
||||
if // err 用于本次流程后续判断的err
|
||||
err := n.SendToChannel(1, "x"); err == nil {
|
||||
t.Fatal("store 为 nil 应报错")
|
||||
}
|
||||
|
||||
// s、cleanup 保存s、cleanup,供当前处理流程使用
|
||||
// s、cleanup 用于本次流程后续判断的s、cleanup
|
||||
s, cleanup := newNotifyStoreBare(t)
|
||||
defer cleanup()
|
||||
// n2 保存n2,供当前处理流程使用
|
||||
// n2 用于本次流程后续判断的n2
|
||||
n2 := New("cid", s, nil)
|
||||
// 不存在的渠道 ID。
|
||||
if err := n2.SendToChannel(99999, "x"); err == nil {
|
||||
@@ -316,11 +316,11 @@ func TestSendToChannel_Errors(t *testing.T) {
|
||||
|
||||
// TestNotifyDelivery_MultiChannel 某渠道失败不影响其他渠道。
|
||||
func TestNotifyDelivery_MultiChannel(t *testing.T) {
|
||||
// s、cleanup 保存s、cleanup,供当前处理流程使用
|
||||
// s、cleanup 用于本次流程后续判断的s、cleanup
|
||||
s, cleanup := newNotifyStoreBare(t)
|
||||
defer cleanup()
|
||||
|
||||
// okCount 保存ok数量,供当前处理流程使用
|
||||
// okCount 用于本次流程后续判断的ok数量
|
||||
var okCount int32
|
||||
// 成功渠道。
|
||||
okSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -339,10 +339,10 @@ func TestNotifyDelivery_MultiChannel(t *testing.T) {
|
||||
addWebhookChannel(t, s, "cid", "成功渠道", okSrv.URL)
|
||||
addWebhookChannel(t, s, "cid", "失败渠道", failSrv.URL)
|
||||
|
||||
// n 保存n,供当前处理流程使用
|
||||
// n 用于本次流程后续判断的n
|
||||
n := New("cid", s, nil)
|
||||
n.NotifyDelivery("cid", "买家", "b1", "item1", "成功", "chat1")
|
||||
if // got 保存got,供当前处理流程使用
|
||||
if // got 用于本次流程后续判断的got
|
||||
got := atomic.LoadInt32(&okCount); got != 1 {
|
||||
t.Errorf("成功渠道应收到 1 次,实际 %d", got)
|
||||
}
|
||||
@@ -350,15 +350,15 @@ func TestNotifyDelivery_MultiChannel(t *testing.T) {
|
||||
|
||||
// TestNotifyDelivery_TemplateVars 通知正文应包含买家名、商品ID、结果等变量。
|
||||
func TestNotifyDelivery_TemplateVars(t *testing.T) {
|
||||
// s、cleanup 保存s、cleanup,供当前处理流程使用
|
||||
// s、cleanup 用于本次流程后续判断的s、cleanup
|
||||
s, cleanup := newNotifyStoreBare(t)
|
||||
defer cleanup()
|
||||
|
||||
// gotBody 保存got请求体,供当前处理流程使用
|
||||
// gotBody 用于本次流程后续判断的got请求体
|
||||
var gotBody string
|
||||
// srv 保存srv,供当前处理流程使用
|
||||
// srv 用于本次流程后续判断的srv
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
// b 保存b,供当前处理流程使用
|
||||
// b 用于本次流程后续判断的b
|
||||
b, _ := io.ReadAll(r.Body)
|
||||
gotBody = string(b)
|
||||
w.WriteHeader(200)
|
||||
@@ -366,7 +366,7 @@ func TestNotifyDelivery_TemplateVars(t *testing.T) {
|
||||
defer srv.Close()
|
||||
|
||||
addWebhookChannel(t, s, "cid", "模板渠道", srv.URL)
|
||||
// n 保存n,供当前处理流程使用
|
||||
// n 用于本次流程后续判断的n
|
||||
n := New("cid", s, nil)
|
||||
n.NotifyDelivery("cid", "张三", "BID123", "ITEM456", "发货成功", "CHAT789")
|
||||
|
||||
@@ -380,15 +380,15 @@ func TestNotifyDelivery_TemplateVars(t *testing.T) {
|
||||
|
||||
// TestNotifyDelivery_EmptyChatID chatID 为空时回退为“未知”。
|
||||
func TestNotifyDelivery_EmptyChatID(t *testing.T) {
|
||||
// s、cleanup 保存s、cleanup,供当前处理流程使用
|
||||
// s、cleanup 用于本次流程后续判断的s、cleanup
|
||||
s, cleanup := newNotifyStoreBare(t)
|
||||
defer cleanup()
|
||||
|
||||
// gotBody 保存got请求体,供当前处理流程使用
|
||||
// gotBody 用于本次流程后续判断的got请求体
|
||||
var gotBody string
|
||||
// srv 保存srv,供当前处理流程使用
|
||||
// srv 用于本次流程后续判断的srv
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
// b 保存b,供当前处理流程使用
|
||||
// b 用于本次流程后续判断的b
|
||||
b, _ := io.ReadAll(r.Body)
|
||||
gotBody = string(b)
|
||||
w.WriteHeader(200)
|
||||
@@ -396,7 +396,7 @@ func TestNotifyDelivery_EmptyChatID(t *testing.T) {
|
||||
defer srv.Close()
|
||||
|
||||
addWebhookChannel(t, s, "cid", "渠道", srv.URL)
|
||||
// n 保存n,供当前处理流程使用
|
||||
// n 用于本次流程后续判断的n
|
||||
n := New("cid", s, nil)
|
||||
n.NotifyDelivery("cid", "买家", "b1", "item1", "结果", "")
|
||||
if !strings.Contains(gotBody, "未知") {
|
||||
@@ -447,7 +447,7 @@ func TestNotifyAutomationRunQueuesEachTerminalStateOnce(t *testing.T) {
|
||||
|
||||
// TestParseConfig_InvalidJSON 非法 JSON 走旧格式兼容分支。
|
||||
func TestParseConfig_InvalidJSON(t *testing.T) {
|
||||
// m 保存m,供当前处理流程使用
|
||||
// m 用于本次流程后续判断的m
|
||||
m := parseConfig("{not json")
|
||||
if m["config"] != "{not json" {
|
||||
t.Errorf("非法 JSON 应放入 config: %v", m)
|
||||
@@ -456,25 +456,25 @@ func TestParseConfig_InvalidJSON(t *testing.T) {
|
||||
|
||||
// TestStrOr 覆盖 string / 非 string / 缺失三个分支。
|
||||
func TestStrOr(t *testing.T) {
|
||||
// m 保存m,供当前处理流程使用
|
||||
// m 用于本次流程后续判断的m
|
||||
m := map[string]any{
|
||||
"s": "abc",
|
||||
"n": 42,
|
||||
"b": true,
|
||||
}
|
||||
if // got 保存got,供当前处理流程使用
|
||||
if // got 用于本次流程后续判断的got
|
||||
got := strOr(m, "s", "x"); got != "abc" {
|
||||
t.Errorf("strOr(s)=%q", got)
|
||||
}
|
||||
if // got 保存got,供当前处理流程使用
|
||||
if // got 用于本次流程后续判断的got
|
||||
got := strOr(m, "n", "x"); got != "42" {
|
||||
t.Errorf("strOr(n)=%q", got)
|
||||
}
|
||||
if // got 保存got,供当前处理流程使用
|
||||
if // got 用于本次流程后续判断的got
|
||||
got := strOr(m, "b", "x"); got != "true" {
|
||||
t.Errorf("strOr(b)=%q", got)
|
||||
}
|
||||
if // got 保存got,供当前处理流程使用
|
||||
if // got 用于本次流程后续判断的got
|
||||
got := strOr(m, "missing", "def"); got != "def" {
|
||||
t.Errorf("strOr(missing)=%q", got)
|
||||
}
|
||||
@@ -482,11 +482,11 @@ func TestStrOr(t *testing.T) {
|
||||
|
||||
// TestFallback fallback 空串与非空串。
|
||||
func TestFallback(t *testing.T) {
|
||||
if // got 保存got,供当前处理流程使用
|
||||
if // got 用于本次流程后续判断的got
|
||||
got := fallback("", "默认"); got != "默认" {
|
||||
t.Errorf("fallback('')=%q", got)
|
||||
}
|
||||
if // got 保存got,供当前处理流程使用
|
||||
if // got 用于本次流程后续判断的got
|
||||
got := fallback("值", "默认"); got != "值" {
|
||||
t.Errorf("fallback('值')=%q", got)
|
||||
}
|
||||
@@ -494,13 +494,13 @@ func TestFallback(t *testing.T) {
|
||||
|
||||
// TestNotifyAccountAlert_DBError 查询出错时不 panic(err != nil 分支)。
|
||||
func TestNotifyAccountAlert_DBError(t *testing.T) {
|
||||
// s、cleanup 保存s、cleanup,供当前处理流程使用
|
||||
// s、cleanup 用于本次流程后续判断的s、cleanup
|
||||
s, cleanup := newNotifyStoreBare(t)
|
||||
// d 保存d,供当前处理流程使用
|
||||
// d 用于本次流程后续判断的d
|
||||
d := s.DB
|
||||
cleanup() // 提前关闭 DB,使查询返回错误
|
||||
_ = d
|
||||
// n 保存n,供当前处理流程使用
|
||||
// n 用于本次流程后续判断的n
|
||||
n := New("cid", s, nil)
|
||||
// store 非 nil 但 DB 已关闭,查询会报错;不应 panic。
|
||||
n.NotifyAccountAlert("cid", "warn", "标题", "正文")
|
||||
@@ -508,7 +508,7 @@ func TestNotifyAccountAlert_DBError(t *testing.T) {
|
||||
|
||||
// TestNotifyDelivery_DBError 查询出错时不 panic(err != nil 分支)。
|
||||
func TestNotifyDelivery_DBError(t *testing.T) {
|
||||
// s、cleanup 保存s、cleanup,供当前处理流程使用
|
||||
// s、cleanup 用于本次流程后续判断的s、cleanup
|
||||
s, cleanup := newNotifyStoreBare(t)
|
||||
cleanup() // 提前关闭 DB
|
||||
n := New("cid", s, nil)
|
||||
@@ -517,11 +517,11 @@ func TestNotifyDelivery_DBError(t *testing.T) {
|
||||
|
||||
// TestSendToChannel_DBError 查询渠道出错时返回包装错误。
|
||||
func TestSendToChannel_DBError(t *testing.T) {
|
||||
// s、cleanup 保存s、cleanup,供当前处理流程使用
|
||||
// s、cleanup 用于本次流程后续判断的s、cleanup
|
||||
s, cleanup := newNotifyStoreBare(t)
|
||||
cleanup() // 提前关闭 DB
|
||||
n := New("cid", s, nil)
|
||||
if // err 保存err,供当前处理流程使用
|
||||
if // err 用于本次流程后续判断的err
|
||||
err := n.SendToChannel(1, "x"); err == nil {
|
||||
t.Fatal("DB 查询出错应返回 error")
|
||||
}
|
||||
@@ -529,18 +529,18 @@ func TestSendToChannel_DBError(t *testing.T) {
|
||||
|
||||
// TestNotifyAccountAlert_SendError 某渠道发送失败时记录错误但不中断。
|
||||
func TestNotifyAccountAlert_SendError(t *testing.T) {
|
||||
// s、cleanup 保存s、cleanup,供当前处理流程使用
|
||||
// s、cleanup 用于本次流程后续判断的s、cleanup
|
||||
s, cleanup := newNotifyStoreBare(t)
|
||||
defer cleanup()
|
||||
|
||||
// srv 保存srv,供当前处理流程使用
|
||||
// srv 用于本次流程后续判断的srv
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
addWebhookChannel(t, s, "cid", "失败渠道", srv.URL)
|
||||
// n 保存n,供当前处理流程使用
|
||||
// n 用于本次流程后续判断的n
|
||||
n := New("cid", s, nil)
|
||||
// 渠道返回 5xx,send 报错 → 走 logger.Error 分支,但不应 panic。
|
||||
n.NotifyAccountAlert("cid", "warn", "标题", "正文")
|
||||
@@ -548,10 +548,10 @@ func TestNotifyAccountAlert_SendError(t *testing.T) {
|
||||
|
||||
// TestNew_DefaultLogger logger 为 nil 时使用默认 logger。
|
||||
func TestNew_DefaultLogger(t *testing.T) {
|
||||
// s、cleanup 保存s、cleanup,供当前处理流程使用
|
||||
// s、cleanup 用于本次流程后续判断的s、cleanup
|
||||
s, cleanup := newNotifyStoreBare(t)
|
||||
defer cleanup()
|
||||
// n 保存n,供当前处理流程使用
|
||||
// n 用于本次流程后续判断的n
|
||||
n := New("cid", s, nil)
|
||||
if n == nil || n.logger == nil || n.httpc == nil {
|
||||
t.Fatal("New 未正确初始化字段")
|
||||
|
||||
Reference in new issue
Block a user