33 lines
1.0 KiB
JavaScript
33 lines
1.0 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import { spawnSync } from "node:child_process";
|
|
import test from "node:test";
|
|
import { buildRemoteStatusScript } from "./status.mjs";
|
|
|
|
test("生产状态脚本不再要求 VPS 上运行 CI runner", () => {
|
|
const script = buildRemoteStatusScript();
|
|
|
|
assert.doesNotMatch(script, /gitea-runner/);
|
|
assert.match(script, /pm2 pid personal-brand-api/);
|
|
assert.match(script, /pg_restore -l/);
|
|
});
|
|
|
|
test("生产状态脚本语法有效", () => {
|
|
const result = spawnSync("bash", ["-n"], {
|
|
input: buildRemoteStatusScript(),
|
|
encoding: "utf8",
|
|
});
|
|
|
|
assert.equal(result.status, 0, result.stderr);
|
|
});
|
|
|
|
test("生产状态脚本使用调用方指定的部署目录", () => {
|
|
const script = buildRemoteStatusScript({ deployRoot: "/srv/personal-brand" });
|
|
|
|
assert.match(script, /DEPLOY_ROOT='\/srv\/personal-brand'/);
|
|
assert.match(script, /"\$DEPLOY_ROOT\/current"/);
|
|
});
|
|
|
|
test("非法部署目录会被拒绝", () => {
|
|
assert.throws(() => buildRemoteStatusScript({ deployRoot: "/srv/personal brand" }), /Invalid/);
|
|
});
|