build: add server-rs test scripts

This commit is contained in:
2026-04-21 01:42:47 +08:00
parent 440d60d563
commit 6a560236f4
5 changed files with 96 additions and 3 deletions

View File

@@ -117,7 +117,8 @@
- [x] 新增本地开发脚本
交付物:[../server-rs/scripts/dev.ps1](../server-rs/scripts/dev.ps1)、[../server-rs/scripts/dev.sh](../server-rs/scripts/dev.sh)
- [ ] 新增测试脚本
- [x] 新增测试脚本
交付物:[../server-rs/scripts/test.ps1](../server-rs/scripts/test.ps1)、[../server-rs/scripts/test.sh](../server-rs/scripts/test.sh)
- [ ] 新增 lint / fmt / clippy / check 脚本
- [ ] 新增 smoke 脚本
- [ ] 新增 SpacetimeDB 本地开发脚本

View File

@@ -14,7 +14,7 @@
## 2. 当前阶段说明
当前目录已经完成以下二十项初始化:
当前目录已经完成以下二十项初始化:
1. 为新后端预留正式目录并把路径固定到仓库结构中。
2. 创建虚拟 workspace `Cargo.toml`,后续 package 会逐项挂入。
@@ -42,10 +42,12 @@
24. 创建 `packages/tests-support/` 目录占位,固定测试支撑共享 package 落位。
25. 创建 `scripts/dev.ps1`,固定 Windows 本地开发入口。
26. 创建 `scripts/dev.sh`,固定 Unix-like 本地开发入口。
27. 创建 `scripts/test.ps1`,固定 Windows 本地测试入口。
28. 创建 `scripts/test.sh`,固定 Unix-like 本地测试入口。
后续任务会继续在本目录内按顺序补齐:
1. 测试、lint、smoke 与 SpacetimeDB 本地脚本
1. lint、smoke 与 SpacetimeDB 本地脚本
## 3. 已冻结边界

View File

@@ -12,6 +12,7 @@
4. 中间件挂载
5. `/healthz``/api/*`、SSE 与静态资源兼容层装配
6.`../../scripts/dev.ps1``../../scripts/dev.sh` 驱动的本地开发启动链路
7.`../../scripts/test.ps1``../../scripts/test.sh` 驱动的本地测试链路
## 2. 当前阶段说明

View File

@@ -0,0 +1,49 @@
[CmdletBinding()]
param(
[Alias("h")]
[switch]$Help,
[string]$Package = ""
)
$ErrorActionPreference = "Stop"
function Write-Usage {
@(
'Usage:'
' ./server-rs/scripts/test.ps1'
' ./server-rs/scripts/test.ps1 -Package api-server'
''
'Notes:'
' 1. Run cargo test for the server-rs workspace by default'
' 2. Use -Package to target one workspace package only'
) -join [Environment]::NewLine
}
if ($Help) {
Write-Usage
exit 0
}
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$serverRsDir = Split-Path -Parent $scriptDir
$manifestPath = Join-Path $serverRsDir "Cargo.toml"
if (-not (Test-Path $manifestPath)) {
throw "Missing server-rs/Cargo.toml, cannot start test script."
}
Write-Host "[server-rs:test] working dir: $serverRsDir"
Push-Location $serverRsDir
try {
if ([string]::IsNullOrWhiteSpace($Package)) {
cargo test --manifest-path $manifestPath
}
else {
Write-Host "[server-rs:test] target package: $Package"
cargo test -p $Package --manifest-path $manifestPath
}
}
finally {
Pop-Location
}

40
server-rs/scripts/test.sh Normal file
View File

@@ -0,0 +1,40 @@
#!/usr/bin/env bash
set -euo pipefail
usage() {
cat <<'EOF'
Usage:
./server-rs/scripts/test.sh
SERVER_RS_TEST_PACKAGE=api-server ./server-rs/scripts/test.sh
Notes:
1. Run cargo test for the server-rs workspace by default
2. Use SERVER_RS_TEST_PACKAGE to target one workspace package only
EOF
}
if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then
usage
exit 0
fi
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
SERVER_RS_DIR="$(cd -- "${SCRIPT_DIR}/.." && pwd)"
MANIFEST_PATH="${SERVER_RS_DIR}/Cargo.toml"
if [[ ! -f "${MANIFEST_PATH}" ]]; then
echo "[server-rs:test] Missing ${MANIFEST_PATH}, cannot start test script." >&2
exit 1
fi
echo "[server-rs:test] working dir: ${SERVER_RS_DIR}"
cd "${SERVER_RS_DIR}"
if [[ -n "${SERVER_RS_TEST_PACKAGE:-}" ]]; then
echo "[server-rs:test] target package: ${SERVER_RS_TEST_PACKAGE}"
cargo test -p "${SERVER_RS_TEST_PACKAGE}" --manifest-path "${MANIFEST_PATH}"
else
cargo test --manifest-path "${MANIFEST_PATH}"
fi