Commit c761952e by luoqi

merge: test PAC migration failure protection

parents eaf31b3c 9cef8091
Pipeline #3719 failed in 0 seconds
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, copyFileSync, rmSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join, resolve } from 'node:path';
import { spawnSync } from 'node:child_process';
test('PAC 迁移失败保留应用和已运行的基础设施', () => {
const root = mkdtempSync(join(tmpdir(), 'pac-migration-failure-'));
try {
for (const d of ['bin', '.git', 'deploy', 'apps/pac-service']) mkdirSync(join(root, d), { recursive: true });
copyFileSync(resolve('deploy/deploy-prod.sh'), join(root, 'deploy/deploy-prod.sh'));
writeFileSync(join(root, 'apps/pac-service/.env'), 'DATABASE_URL=postgresql://dev:dev@localhost:5432/pac\n');
const log = join(root, 'calls');
writeFileSync(log, '');
for (const [name, body] of Object.entries({
git: 'case "$*" in "rev-parse --git-common-dir") echo .git;; "rev-parse --abbrev-ref HEAD") echo test;; esac',
flock: 'exit 0',
docker: 'echo "$*" >> "$TEST_CALLS"\ncase "$*" in *"ps -q --status running"*) echo existing;; *"run --rm --no-deps pac-migrate"*) exit 42;; esac',
})) writeFileSync(join(root, 'bin', name), '#!/bin/sh\n' + body + '\n', { mode: 0o755 });
const r = spawnSync('bash', ['deploy/deploy-prod.sh', '--no-pull'], {
cwd: root, encoding: 'utf8', env: { ...process.env, COMPOSE_MANAGED: '0', PATH: join(root, 'bin') + ':' + process.env.PATH, TEST_CALLS: log },
});
assert.equal(r.status, 42, r.stdout + r.stderr);
const calls = readFileSync(log, 'utf8');
assert.match(calls, /run --rm --no-deps pac-migrate/);
assert.doesNotMatch(calls, /\b(up|stop|restart|rm)\b.*(pac-service|pac-web|postgres|redis)/);
} finally { rmSync(root, { recursive: true, force: true }); }
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment