Files
epic-go/internal/logic/cron/third_party_sync_test.go
hu xiaotong fc41c5ca73 refactor(internal): 优化 OSS 预签名 URL 缓存刷新任务和英雄数据缓存逻辑
- 注释掉 OSS预签名 URL 缓存刷新任务的定时执行代码
- 在 hero/hero.go 中增加对 Redis缓存和英雄数据集的非空校验
- 修改 OSS预签名 URL 生成逻辑,自动替换为 CDN 域名
2025-07-25 17:08:39 +08:00

89 lines
2.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package cron
import (
"context"
"epic/internal/logic/i18n"
"fmt"
_ "github.com/gogf/gf/contrib/drivers/mysql/v2"
_ "github.com/gogf/gf/contrib/nosql/redis/v2"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gctx"
"github.com/gogf/gf/v2/os/genv"
"os"
"testing"
)
func TestMain(m *testing.M) {
// 必须在任何import和g.Cfg()调用前设置环境变量
genv.Set("GF_GCFG_FILE", "../../../../manifest/config/config.yaml")
ctx := gctx.New()
_ = g.Cfg().MustGet(ctx, "server.address")
fmt.Println(g.Cfg().Get(ctx, "redis.default.address"))
code := m.Run()
os.Exit(code)
}
/**
* 测试同步英雄数据
*/
func TestI18n(t *testing.T) {
_ = i18n.RefreshI18n(context.Background())
fmt.Println(i18n.Zh2En("湖畔魔女泰妮布里雅"))
}
/**
* 测试同步英雄数据
*/
func TestSyncHeroData(t *testing.T) {
_ = i18n.RefreshI18n(context.Background())
thirdPartyDataSync := NewThirdPartyDataSync()
err := thirdPartyDataSync.SyncHeroData(context.Background())
if err != nil {
t.Errorf("expected success, got error: %v", err)
}
}
/**
* 测试同步神器数据
*/
func TestSyncArtifactData_Success(t *testing.T) {
_ = i18n.RefreshI18n(context.Background())
sync := NewThirdPartyDataSync()
err := sync.SyncArtifactData(context.Background())
if err != nil {
t.Errorf("expected success, but got error: %v", err)
}
}
func TestInitI18nStaticToDB(t *testing.T) {
//t.Skip("仅初始化时手动执行一次,谨慎运行!")
ctx := context.Background()
// 直接批量导入,不做重复检查
err := i18n.ImportI18nFromMap(ctx, "zh", i18n.I18nEnToZh, "init")
if err != nil {
t.Fatalf("导入静态i18n数据失败: %v", err)
}
t.Logf("静态i18n数据导入成功共%d条", len(i18n.I18nEnToZh))
}
func TestSyncI18nFromRemote(t *testing.T) {
ctx := context.Background()
logic := i18n.GetI18nLogic()
err := logic.SyncI18nFromRemote(ctx)
if err != nil {
t.Fatalf("远程i18n数据同步失败: %v", err)
}
t.Logf("远程i18n数据同步成功")
}
func TestFixHeroAndArtifactNameToChinese(t *testing.T) {
ctx := context.Background()
err := FixHeroAndArtifactNameToChinese(ctx)
if err != nil {
t.Fatalf("修复英雄/神器中文名失败: %v", err)
}
t.Logf("修复英雄/神器中文名成功")
}