Files
ez-api/TESTING.md
zenfun d0011f3eb2 test: add comprehensive unit tests for provider, middleware, and sync service
- 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
2025-12-14 00:35:35 +08:00

1.2 KiB
Raw Blame History

Testing (ez-api)

本仓库的单元测试采用 Go 标准组织方式:单元测试与源码同目录(*_test.go),默认通过 go test ./... 运行。

此外,本仓库仍保留 ./test 下的 docker-compose 集成测试(带 integration tag用于端到端验证。

运行

单元测试

go test ./...

集成测试docker compose

./test/integration.sh

说明

  • 单元测试不依赖 Docker不访问公网。
  • 对 Redis 相关逻辑优先使用 miniredis(纯内存、接近真实命令行为)。
  • 对 DB 相关逻辑优先使用 sqlite in-memory只用于测试避免引入外部依赖。

分阶段计划(长期)

阶段 1已落地/优先级最高)

  • provider 归一化Vertex 默认 google_location=global 的回归保护
  • SyncServiceRedis snapshot 写入与 routing key 生成
  • request_idGin middleware 透传/生成

阶段 2扩覆盖

  • Master/Keytoken hash、epoch、scope、状态机分支
  • LogWriter批处理/刷盘边界(可用 fake clock

阶段 3契约测试

  • 与 DP 的 snapshot schema 契约:用 testdata golden 校验字段/格式稳定