mirror of
https://github.com/EZ-Api/ez-api.git
synced 2026-01-13 17:47:51 +00:00
- Add TESTING.md documentation explaining unit test conventions and integration testing setup - Add miniredis and sqlite dependencies to go.mod for in-memory testing - Add provider_handler_test.go ensuring Vertex providers default google_location to "global" - Add request_id_test.go verifying request ID generation and header preservation - Add sync_test.go validating Redis snapshot writes and routing key generation - Update README.md with testing section referencing new documentation
44 lines
1.2 KiB
Markdown
44 lines
1.2 KiB
Markdown
# Testing (ez-api)
|
||
|
||
本仓库的单元测试采用 Go 标准组织方式:单元测试与源码同目录(`*_test.go`),默认通过 `go test ./...` 运行。
|
||
|
||
此外,本仓库仍保留 `./test` 下的 docker-compose 集成测试(带 `integration` tag),用于端到端验证。
|
||
|
||
## 运行
|
||
|
||
### 单元测试
|
||
|
||
```bash
|
||
go test ./...
|
||
```
|
||
|
||
### 集成测试(docker compose)
|
||
|
||
```bash
|
||
./test/integration.sh
|
||
```
|
||
|
||
## 说明
|
||
|
||
- 单元测试不依赖 Docker,不访问公网。
|
||
- 对 Redis 相关逻辑优先使用 `miniredis`(纯内存、接近真实命令行为)。
|
||
- 对 DB 相关逻辑优先使用 sqlite in-memory(只用于测试),避免引入外部依赖。
|
||
|
||
## 分阶段计划(长期)
|
||
|
||
### 阶段 1(已落地/优先级最高)
|
||
|
||
- provider 归一化:Vertex 默认 `google_location=global` 的回归保护
|
||
- SyncService:Redis snapshot 写入与 routing key 生成
|
||
- request_id:Gin middleware 透传/生成
|
||
|
||
### 阶段 2(扩覆盖)
|
||
|
||
- Master/Key:token hash、epoch、scope、状态机分支
|
||
- LogWriter:批处理/刷盘边界(可用 fake clock)
|
||
|
||
### 阶段 3(契约测试)
|
||
|
||
- 与 DP 的 snapshot schema 契约:用 `testdata` golden 校验字段/格式稳定
|
||
|