- Every command takes --json (crosscode.script-report/1 on stdout, the log on stderr) and --config (the .env values by layer, from the agent). - .env files come from the release's env.template.json (lib/envtpl.js): written whole on install; on deploy only new variables are appended, and a new required one with no value stops the deploy at the checks. - install --frp: Hub-given ports, a marked frpc.ini block (backup, frpc verify, reload; [common] admin lines added once), no nginx. A database on another server via DB_ADMIN_URL. Refuses an existing database or role. Everything the run made is removed if it fails. - restart, export (crosscode.church-export/1 ZIP), uninstall (final backup, uploads and .env kept 30 days) and purge. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
70 lines
2.4 KiB
Bash
70 lines
2.4 KiB
Bash
#!/usr/bin/env bats
|
|
# --json reports (lib/report.sh) and the argument checks of the new commands (what needs a server
|
|
# is tested on a VM).
|
|
|
|
bats_require_minimum_version 1.5.0
|
|
|
|
setup() {
|
|
export CROSSCODE_NO_UPDATE=1
|
|
CC="$BATS_TEST_DIRNAME/../crosscode"
|
|
}
|
|
|
|
json() { node -e 'let s="";process.stdin.on("data",d=>s+=d).on("end",()=>{const v=process.argv[1].split(".").reduce((o,k)=>o==null?o:o[k],JSON.parse(s));process.stdout.write(typeof v==="object"?JSON.stringify(v):String(v))})' "$1"; }
|
|
|
|
@test "--json: one report on stdout, the log on stderr" {
|
|
run --separate-stderr bash "$CC" help --json
|
|
[ "$status" -eq 0 ]
|
|
[ "$(printf '%s' "$output" | json schema)" = "crosscode.script-report/1" ]
|
|
[ "$(printf '%s' "$output" | json status)" = "succeeded" ]
|
|
[ "$(printf '%s' "$output" | json command)" = "help" ]
|
|
[[ "$stderr" == *"crosscode deploy <church>"* ]]
|
|
}
|
|
|
|
@test "--json on a failure: status failed and the reason" {
|
|
run --separate-stderr bash "$CC" uninstall hope --json
|
|
[ "$status" -eq 1 ]
|
|
[ "$(printf '%s' "$output" | json status)" = "failed" ]
|
|
[[ "$(printf '%s' "$output" | json message)" == *"--confirm hope"* ]]
|
|
}
|
|
|
|
@test "--config must be an existing JSON file" {
|
|
run bash "$CC" status --config /nonexistent.json
|
|
[ "$status" -eq 1 ]
|
|
[[ "$output" == *"no file /nonexistent.json"* ]]
|
|
echo 'not json' > "$BATS_TEST_TMPDIR/c.json"
|
|
run bash "$CC" status --config "$BATS_TEST_TMPDIR/c.json"
|
|
[ "$status" -eq 1 ]
|
|
[[ "$output" == *"isn't JSON"* ]]
|
|
}
|
|
|
|
@test "uninstall and purge need --confirm with the church's own name" {
|
|
run bash "$CC" uninstall hope
|
|
[ "$status" -eq 1 ]
|
|
[[ "$output" == *"add --confirm hope"* ]]
|
|
run bash "$CC" uninstall hope --confirm other
|
|
[ "$status" -eq 1 ]
|
|
run bash "$CC" purge hope
|
|
[ "$status" -eq 1 ]
|
|
[[ "$output" == *"add --confirm hope"* ]]
|
|
}
|
|
|
|
@test "export needs an absolute .zip path" {
|
|
run bash "$CC" export hope --out relative.zip
|
|
[ "$status" -eq 1 ]
|
|
[[ "$output" == *"absolute path ending in .zip"* ]]
|
|
}
|
|
|
|
@test "install --frp needs the ports from the Hub" {
|
|
run bash "$CC" install hope --products events --domain hope.co.za --frp
|
|
[ "$status" -eq 1 ]
|
|
[[ "$output" == *"--frp needs --api-port and --web-port"* ]]
|
|
}
|
|
|
|
@test "help lists the new commands" {
|
|
run bash "$CC" help
|
|
[[ "$output" == *"crosscode uninstall <church> --confirm <church>"* ]]
|
|
[[ "$output" == *"--json"* ]]
|
|
run bash "$CC" help export
|
|
[[ "$output" == *"crosscode.church-export/1"* ]]
|
|
}
|