SuperAPI AI 工具集

mongo-tools-js-to-go

测试与质量

查看项目

更新于 10-16 01:19

技能介绍

用途:把 mongo-tools 仓库中的 JS/resmoke 集成测试迁移为 Go testify 测试。

主要能力:区分两类测试形式——工具包内的单工具测试使用 func TestFoo(t *testing.T),全流程端到端测试(dump+restore、export+import)放入 integration/dumprestore 或 integration/exportimport 的 testify suite。提供测试类型常量(IntegrationTestType、ReplSetTestType、ShardedIntegrationTestType、SSLTestType、AuthTestType)、套件方法(s.Context、s.Client、s.DBName、s.Require、s.Assert、s.T、s.Run)以及辅助函数(testutil.GetBareSessionProvider、testutil.GetToolOptions、testutil.GetBareArgs、runImportOpts、importWithIngestOpts、testutil.AssertBrokenPipeHandled)。

使用方式:先读 JS 测试并确认所需 testtype,再决定用套件方法还是包内普通测试;往返测试需在导出/转储与导入/恢复之间删除集合;JSON 测试文件用 Go 数据结构加 json.Marshal 生成,保留 BSON 类型时用 bson.MarshalExtJSON。本地运行:TOOLS_TESTING_INTEGRATION=true go test ./mongoimport/... -v -run TestFoo -count=1;套件测试:TOOLS_TESTING_INTEGRATION=true go test ./integration/dumprestore/... -v -run TestDumpRestore/TestFoo -count=1;认证环境追加 TOOLS_TESTING_AUTH=1 等变量。提交前用 precious tidy -g 自动修复格式,precious lint -g 检查。

代码约定:调用者在前、被调用者在后;不写描述性注释;用 any 代替 interface{};断言必须带说明信息;每次 Decode 前重置 map[string]any{};表驱动测试定义 fooCase 结构体;错误断言用 require.ErrorIs、require.ErrorAs 或 require.ErrorContains。

限制:套件测试无需手动清理数据库,BeforeTest 会删除非系统库,不要在套件测试中注册 t.Cleanup 删除数据库;提交信息需以 TOOLS 工单号开头;删除 JS 文件前需询问用户。具体工单号、认证凭据等未提供。