Files
rill/internal/api/api_test.go
T
kevin 6f8edb16a8 页脚展示前后端版本与构建信息
- 新增 internal/version 包维护服务端版本(默认 0.1.0,可用 -ldflags -X 覆盖),GET /api/health 返回 version 字段
- main.go Swagger @version 与常量对齐为 0.1.0,重新生成 docs;api_test 增加版本断言
- 前端 package.json 升至 0.1.0,Vite 注入版本、git 短哈希与构建时间(无 git 自动省略哈希)
- 新增 api/version.ts 与 version store,启动时从 health 读取后端版本(失败显示 —)
- 页脚左下角显示“前端 vX | 后端 vY | 构建 +hash · 时间”,三语文案补齐
2026-09-22 12:04:04 +08:00

31 lines
718 B
Go

package api_test
import (
"encoding/json"
"net/http"
"testing"
"rill/internal/testutil"
"rill/internal/version"
)
func TestHealth(t *testing.T) {
env := testutil.Setup(t)
w := testutil.Call(t, env.Router(""), http.MethodGet, "/api/health", nil)
if w.Code != http.StatusOK {
t.Fatalf("状态码 = %d, 期望 %d, body=%s", w.Code, http.StatusOK, w.Body.String())
}
var resp map[string]string
if err := json.Unmarshal(w.Body.Bytes(), &resp); err != nil {
t.Fatalf("解析响应失败: %v", err)
}
if resp["status"] != "ok" {
t.Errorf("status = %q, 期望 ok", resp["status"])
}
if resp["version"] != version.Version {
t.Errorf("version = %q, 期望 %q", resp["version"], version.Version)
}
}