git2go 库的可视化测试工具,提供 Web 界面对 git2go 的 API 进行交互式测试。
# 1. 克隆 git2go-tester
git clone https://cnb.cool/cnb/git2go-tester
cd git2go-tester
# 2. 直接运行(脚本会自动拉依赖、编译 libgit2、启动服务)
./run.sh
浏览器访问 http://localhost:7070
说明:首次运行会自动下载 git2go v35.1.1 并编译 libgit2 静态库,大约需要 2-5 分钟。 后续重启只需重新执行
./run.sh,检测到静态库已存在则跳过编译。
git2go-tester/ ├── run.sh # 启动脚本(拉依赖→编译→运行) ├── go.mod # Go 模块定义 ├── server.go # HTTP Server、路由、Session 管理 ├── testcase.go # 所有测试用例定义 ├── index.go # 前端 HTML 嵌入(go:embed) └── static/ └── index.html # 前端单页面
HTTP 路由:
| 路由 | 方法 | 说明 |
|---|---|---|
/ | GET | 返回前端页面 |
/api/session | POST | 创建新 session,返回 sid |
/api/groups | GET | 返回所有测试分组和用例(含状态) |
/api/run | POST | 执行测试,支持指定 group/name 或全部 |
/api/result | GET | 获取单个测试结果 |
/api/results | GET | 获取当前 session 所有结果 |
/api/clear | POST | 清除当前 session 所有结果 |
Session 隔离:
X-Session-ID header 或 ?sid= 参数传递 sid并发执行:
测试用例(testcase.go):
TestCase 结构体,包含名称、分组、描述、流程步骤(Flow)、执行函数Flow []FlowStep 定义执行步骤,前端据此画流程图tempRepo() / seedCommit() 提供隔离的临时仓库纯原生 JS + CSS,无任何框架依赖,单文件约 700 行。
布局:
流程图渲染:
flow 数组动态生成input📥 / call⚙️ / output📤 / check✅ / error❌ / data📋接口说明: