mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-01 06:36:38 +08:00
2f60329886
代码质量全量清理,零行为变化:golangci 扩展集 13 类 linter(gosec/modernize/perfsprint/canonicalheader/usestdlibvars/wastedassign/intrange/errorlint/forcetypeassert/recvcheck/exhaustive/unparam)全量修复,测试代码质量(testifylint/thelper/usetesting)25→0,frpc 进程生命周期真 bug(进程组击杀)、全仓 go test -race 6 类数据竞争(含 1 个生产竞争)、SPDX license 头补齐 131 文件、前端测试套件 next-intl 迁移后 44 失败→全绿、过期 swagger 文档重新生成、pnpm-workspace 构建审批。 Experiments: #2-#17, #18, #20, #21, #23 Metric: total_issues 108 → 8 (-92.6%)
77 lines
2.4 KiB
Go
77 lines
2.4 KiB
Go
// Copyright 2026 Arctel.net
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package task
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/Rain-kl/Wavelet/internal/infra/config"
|
|
"github.com/redis/go-redis/v9"
|
|
"github.com/redis/go-redis/v9/maintnotifications"
|
|
)
|
|
|
|
func TestNewRedisConnOptConfiguresMaintenanceNotifications(t *testing.T) {
|
|
previous := config.Config.Redis
|
|
t.Cleanup(func() { config.Config.Redis = previous })
|
|
|
|
for _, test := range []struct {
|
|
name string
|
|
enabled bool
|
|
want maintnotifications.Mode
|
|
}{
|
|
{name: "disabled by default", enabled: false, want: maintnotifications.ModeDisabled},
|
|
{name: "auto when enabled", enabled: true, want: maintnotifications.ModeAuto},
|
|
} {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
config.Config.Redis.MaintNotifications = test.enabled
|
|
|
|
t.Run("standalone", func(t *testing.T) {
|
|
config.Config.Redis.ClusterMode = false
|
|
config.Config.Redis.MasterName = ""
|
|
config.Config.Redis.Addrs = []string{"127.0.0.1:6379"}
|
|
|
|
client, ok := NewRedisConnOpt().MakeRedisClient().(*redis.Client)
|
|
if !ok {
|
|
t.Fatal("standalone option did not create *redis.Client")
|
|
}
|
|
defer func() { _ = client.Close() }()
|
|
assertMaintenanceNotificationsMode(t, client.Options().MaintNotificationsConfig, test.want)
|
|
})
|
|
|
|
t.Run("cluster", func(t *testing.T) {
|
|
config.Config.Redis.ClusterMode = true
|
|
config.Config.Redis.MasterName = ""
|
|
config.Config.Redis.Addrs = []string{"127.0.0.1:6379"}
|
|
|
|
client, ok := NewRedisConnOpt().MakeRedisClient().(*redis.ClusterClient)
|
|
if !ok {
|
|
t.Fatal("cluster option did not create *redis.ClusterClient")
|
|
}
|
|
defer func() { _ = client.Close() }()
|
|
assertMaintenanceNotificationsMode(t, client.Options().MaintNotificationsConfig, test.want)
|
|
})
|
|
|
|
t.Run("sentinel", func(t *testing.T) {
|
|
config.Config.Redis.ClusterMode = false
|
|
config.Config.Redis.MasterName = "openflare"
|
|
config.Config.Redis.Addrs = []string{"127.0.0.1:26379"}
|
|
|
|
client, ok := NewRedisConnOpt().MakeRedisClient().(*redis.Client)
|
|
if !ok {
|
|
t.Fatal("sentinel option did not create *redis.Client")
|
|
}
|
|
defer func() { _ = client.Close() }()
|
|
assertMaintenanceNotificationsMode(t, client.Options().MaintNotificationsConfig, test.want)
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
func assertMaintenanceNotificationsMode(t *testing.T, cfg *maintnotifications.Config, want maintnotifications.Mode) {
|
|
t.Helper()
|
|
if cfg == nil || cfg.Mode != want {
|
|
t.Fatalf("maintenance notifications mode = %v, want %v", cfg, want)
|
|
}
|
|
}
|