test(watchdog): 整轮巡检测试覆盖集群告警保持、dry-run、主机 relay 密码、按配置检查与状态存不下,收件人查询移入 watchdog 并加 pgint 契约

This commit is contained in:
Lemon-miaow committed 2026-09-27 12:33:11 +08:00
1 parent f9312118c9
commit fe48319866
4 files changed
+309 -21

No files matched your search

+54
View File
@@ -0,0 +1,54 @@
//go:build pgint
package pgint
import (
"context"
"slices"
"strings"
"testing"
"felis.lolicon.best/internal/watchdog"
)
// TestWatchdogOwnerEmails: the watchdog mails the verified address of every enabled
// owner account, in order, and no other account's.
func TestWatchdogOwnerEmails(t *testing.T) {
ctx := context.Background()
tag := suffix(t)
addr := func(who string) string { return who + "-" + tag + "@example.com" }
for _, u := range []struct {
who, role, email string
verified, off bool
deleted bool
}{
{who: "zoe", role: "owner", email: addr("zoe"), verified: true},
{who: "amy", role: "owner", email: addr("amy"), verified: true},
{who: "unverified", role: "owner", email: addr("unverified")},
{who: "disabled", role: "owner", email: addr("disabled"), verified: true, off: true},
{who: "deleted", role: "owner", email: addr("deleted"), verified: true, deleted: true},
{who: "admin", role: "admin", email: addr("admin"), verified: true},
{who: "user", role: "user", email: addr("user"), verified: true},
{who: "no-address", role: "owner", verified: true},
} {
var email any
if u.email != "" {
email = u.email
}
if _, err := db.ExecContext(ctx,
`INSERT INTO users (id, username, role, email, email_verified, disabled, deleted_at)
VALUES ($1, $1, $2, $3, $4, $5, CASE WHEN $6 THEN now() END)`,
"pgint-"+u.who+"-"+tag, u.role, email, u.verified, u.off, u.deleted); err != nil {
t.Fatalf("insert %s: %v", u.who, err)
}
}
got, err := watchdog.OwnerEmails(ctx, db)
if err != nil {
t.Fatal(err)
}
// Other suites share the schema; their accounts carry other tags.
mine := slices.DeleteFunc(got, func(e string) bool { return !strings.Contains(e, tag) })
if want := []string{addr("amy"), addr("zoe")}; !slices.Equal(mine, want) {
t.Fatalf("OwnerEmails = %q, want %q", mine, want)
}
}