Files
epic-go/internal/logic/cron/third_party_sync_test.go
hxt 0ad79c4f27 ci(drone): 添加 Go 模块和构建缓存
- 在 restore cache 和 rebuild cache 步骤中添加了 go-mod-cache 和 go
2025-07-17 20:25:50 +08:00

70 lines
1.7 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) {
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))
}