mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-10-20 16:22:37 +00:00
Caddy 式进程内模块系统(详见 docs/plugin-architecture/MODULE-AUTHOR-GUIDE.md): - internal/plugin:命名空间注册表(init 注册/重复 panic)、Provision→Validate→Start→Stop 生命周期(Start 半途逆序回滚、Stop 逆序+ctx deadline)、Host 四项 ports 能力面、 modules: 配置子树(enabled 三态;viper 含点 key 手工提取)、Runtime 状态机 - internal/plugin/plugintest:模块测试夹具(NewHost Options + RunLifecycle) - internal/modules:standard/imports.go 唯一插装清单 + job.hello 示例模块(默认 disabled) - Wire/main 接入:Build+Start 失败 fail-fast(显式 Cleanup 防 leader 锁泄漏)、 runtime.Stop 在 cleanup 并行组首位(先于 Redis/Ent) - admin 可观测:GET /api/v1/admin/modules(只读,错误文本脱敏) - 默认配置零行为变更(Phase-0 安全网 + bench allocs 零漂移验证) 含两轮对抗式审计修复(1×P1 启动失败泄漏 leader 锁 + 11×P2)与回归测试。
90 lines
2.4 KiB
Go
90 lines
2.4 KiB
Go
package main
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/Wei-Shaw/sub2api/internal/config"
|
|
"github.com/Wei-Shaw/sub2api/internal/handler"
|
|
"github.com/Wei-Shaw/sub2api/internal/service"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestProvideServiceBuildInfo(t *testing.T) {
|
|
in := handler.BuildInfo{
|
|
Version: "v-test",
|
|
BuildType: "release",
|
|
}
|
|
out := provideServiceBuildInfo(in)
|
|
require.Equal(t, in.Version, out.Version)
|
|
require.Equal(t, in.BuildType, out.BuildType)
|
|
}
|
|
|
|
func TestProvideCleanup_WithMinimalDependencies_NoPanic(t *testing.T) {
|
|
cfg := &config.Config{}
|
|
|
|
oauthSvc := service.NewOAuthService(nil, nil)
|
|
openAIOAuthSvc := service.NewOpenAIOAuthService(nil, nil)
|
|
geminiOAuthSvc := service.NewGeminiOAuthService(nil, nil, nil, nil, cfg)
|
|
antigravityOAuthSvc := service.NewAntigravityOAuthService(nil)
|
|
|
|
tokenRefreshSvc := service.NewTokenRefreshService(
|
|
nil,
|
|
oauthSvc,
|
|
openAIOAuthSvc,
|
|
geminiOAuthSvc,
|
|
antigravityOAuthSvc,
|
|
nil,
|
|
nil,
|
|
cfg,
|
|
nil,
|
|
)
|
|
accountExpirySvc := service.NewAccountExpiryService(nil, time.Second)
|
|
proxyExpirySvc := service.NewProxyExpiryService(nil, time.Second)
|
|
subscriptionExpirySvc := service.NewSubscriptionExpiryService(nil, time.Second)
|
|
pricingSvc := service.NewPricingService(cfg, nil)
|
|
emailQueueSvc := service.NewEmailQueueService(nil, 1)
|
|
billingCacheSvc := service.NewBillingCacheService(nil, nil, nil, nil, nil, nil, cfg, nil)
|
|
idempotencyCleanupSvc := service.NewIdempotencyCleanupService(nil, cfg)
|
|
schedulerSnapshotSvc := service.NewSchedulerSnapshotService(nil, nil, nil, nil, cfg)
|
|
opsSystemLogSinkSvc := service.NewOpsSystemLogSink(nil)
|
|
|
|
cleanup := provideCleanup(
|
|
nil, // entClient
|
|
nil, // redis
|
|
&service.OpsMetricsCollector{},
|
|
&service.OpsAggregationService{},
|
|
&service.OpsAlertEvaluatorService{},
|
|
&service.OpsCleanupService{},
|
|
&service.OpsScheduledReportService{},
|
|
opsSystemLogSinkSvc,
|
|
schedulerSnapshotSvc,
|
|
tokenRefreshSvc,
|
|
accountExpirySvc,
|
|
proxyExpirySvc,
|
|
subscriptionExpirySvc,
|
|
&service.UsageCleanupService{},
|
|
idempotencyCleanupSvc,
|
|
pricingSvc,
|
|
emailQueueSvc,
|
|
billingCacheSvc,
|
|
&service.UsageRecordWorkerPool{},
|
|
&service.SubscriptionService{},
|
|
oauthSvc,
|
|
openAIOAuthSvc,
|
|
geminiOAuthSvc,
|
|
antigravityOAuthSvc,
|
|
nil, // openAIGateway
|
|
nil, // scheduledTestRunner
|
|
nil, // backupSvc
|
|
nil, // paymentOrderExpiry
|
|
nil, // channelMonitorRunner
|
|
nil, // quotaFlusher
|
|
nil, // moduleRuntime
|
|
)
|
|
|
|
require.NotPanics(t, func() {
|
|
cleanup()
|
|
})
|
|
}
|