Files
tokens-reef/backend/cmd/server/wire_gen_test.go
pham 0e057904e6
Some checks failed
CI / test (push) Has been cancelled
CI / golangci-lint (push) Has been cancelled
Security Scan / backend-security (push) Has been cancelled
Security Scan / frontend-security (push) Has been cancelled
refactor: 彻底移除 Sora 视频生成模块(全栈清理)
## 后端变更
- 删除 21 个 sora_*.go 服务文件(service/handler/repository/routes)
- 删除 Sora 相关 migration 文件(046/047/063/090)
- 清理 config 中的 sora_* 配置项和平台常量
- 清理 wire 依赖注入中的 Sora 组件
- 修复 wire_gen.go 语法错误(缺少逗号和闭合括号)
- 移除 go.mod 中的 go-sora2api 依赖
- 更新 ent schema usage_log.go 注释

## 前端变更
- 删除 SoraView、SoraAdminView 及 8 个 Sora 子组件
- 删除 sora API 层和路由配置
- 清理 UserEditModal 中的 Sora 存储配额 UI
- 清理 types/index.ts 中 Sora 相关类型定义
- 清理 stores/app.ts 默认配置
- 清理 i18n 翻译文件 en.ts/zh.ts (~110 行)
- 更新相关测试文件

## 文档更新
- README.md / README_CN.md / README_JA.md: 移除 Sora 状态说明和配置段落
- PROJECT_DIFF.md: 移除 Sora 相关差异描述

## 验证结果
-  Go 编译通过 (go build ./...)
-  TypeScript 类型检查通过 (vue-tsc --noEmit)
-  后端测试全通过 (0 failures)
-  前端测试全通过 (59 files, 329 tests, 0 failures)
-  前端生产构建成功 (23.81s)
2026-05-10 14:15:45 +08:00

131 lines
3.3 KiB
Go

package main
import (
"context"
"errors"
"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)
subscriptionExpirySvc := service.NewSubscriptionExpiryService(nil, time.Second)
pricingSvc := service.NewPricingService(cfg, nil)
emailQueueSvc := service.NewEmailQueueService(nil, 1)
billingCacheSvc := service.NewBillingCacheService(nil, nil, nil, nil, cfg)
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,
subscriptionExpirySvc,
&service.UsageCleanupService{},
idempotencyCleanupSvc,
pricingSvc,
emailQueueSvc,
billingCacheSvc,
&service.UsageRecordWorkerPool{},
&service.SubscriptionService{},
oauthSvc,
openAIOAuthSvc,
geminiOAuthSvc,
antigravityOAuthSvc,
nil, // openAIGateway
nil, // scheduledTestRunner
nil, // backupSvc
nil, // paymentOrderExpiry
)
require.NotPanics(t, func() {
cleanup()
})
}
func TestNewBootstrapFunc_RunsDefaultsBeforeRecovery(t *testing.T) {
cfg := &config.Config{}
order := make([]string, 0, 2)
bootstrap := newBootstrapFunc(
func(context.Context) error {
order = append(order, "defaults")
return nil
},
func(_ context.Context, gotRepo service.UserRepository, got *config.Config) error {
require.Nil(t, gotRepo)
require.Same(t, cfg, got)
order = append(order, "recover")
return nil
},
nil,
cfg,
)
require.NoError(t, bootstrap())
require.Equal(t, []string{"defaults", "recover"}, order)
}
func TestNewBootstrapFunc_StopsWhenDefaultsFail(t *testing.T) {
cfg := &config.Config{}
wantErr := errors.New("defaults failed")
recoverCalled := false
bootstrap := newBootstrapFunc(
func(context.Context) error {
return wantErr
},
func(context.Context, service.UserRepository, *config.Config) error {
recoverCalled = true
return nil
},
nil,
cfg,
)
require.ErrorIs(t, bootstrap(), wantErr)
require.False(t, recoverCalled)
}