Files
token_thief/tests/README.md
T

62 lines
1.5 KiB
Markdown
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.
# tests/
集中放置项目的测试代码。每个子目录对应被测包,使用 Go 的黑盒测试包模式(`package xxx_test`)通过被测包的导出 API 进行验证。
## 目录结构
```
tests/
├── config/ # 配置与 glob 过滤器测试
├── logger/ # 异步日志队列与重试逻辑测试
├── proxy/ # 反向代理测试(WebSocket、SSE、上游错误)
└── scripts/ # 手工端到端测试脚本与 DB 校验工具
```
## 运行
```bash
go test ./tests/...
```
或者运行某一个子包:
```bash
go test ./tests/proxy/...
```
## 端到端冒烟测试
先构建本地二进制:
```powershell
go build -o TokenThief.exe .
```
加载 `.env` 并设置 newapi Key
```powershell
. .\tests\scripts\load-env.ps1
$env:NEWAPI_KEY = "sk-..."
```
`.env` 需要包含可写的 `CLICKHOUSE_URL`,例如 `clickhouse://tokenthief:tokenthief@localhost:9000/tokenthief`
运行聊天端点冒烟测试:
```powershell
.\tests\scripts\smoke.ps1 -Model "gpt-5.4-mini"
```
按 request_id 打印数据库里的流式 `response_body`
```powershell
.\tests\scripts\dump-stream-body.ps1 -RequestID "<request_id>"
```
## 构建排除
- 测试目录中的 `_test.go` 文件不会参与 `go build`
- `tests/scripts/` 只放手工测试脚本,不被主程序 import。
- `Dockerfile` 仅构建 main 包(`./`),不会触及 `tests/`
- 仓库根目录的 `.dockerignore``tests/` 整体排除在 build context 之外,镜像中不会包含测试代码或测试脚本。