crosscode uninstall/export/purge <church> [product ...]: with products named only those go and the church keeps the others; naming every product it still has removes the church (folder and app user), so the last product to go takes the church with it. The report gives products and remaining. Uninstalling cross-events-demo's Events removed its Accounts too, which the Hub still showed as live. Contracts 1.16.0: optional products on export/uninstall/purge, PRODUCT_UNINSTALL_MIN_AGENT. Agent 1.5.0 passes them to crosscode. The Website plan moves to contracts 1.17.0 / Hub 2.13.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
103 lines
3.5 KiB
Bash
103 lines
3.5 KiB
Bash
#!/usr/bin/env bats
|
|
# crosscode uninstall / purge (lib/manage.sh) with products named: only those go, and the church
|
|
# keeps the others in church.env. Naming every product removes the church, as before.
|
|
|
|
setup() {
|
|
export CROSSCODE_NO_UPDATE=1 CROSSCODE_TEST=1
|
|
TMP="$BATS_TEST_TMPDIR"
|
|
CALLS="$TMP/calls"
|
|
: > "$CALLS"
|
|
export CROSSCODE_SITES="$TMP/sites" FRPC_INI="$TMP/frpc.ini"
|
|
# shellcheck source=../lib/common.sh
|
|
source "$BATS_TEST_DIRNAME/../lib/common.sh"
|
|
# shellcheck source=../lib/frpc.sh
|
|
source "$BATS_TEST_DIRNAME/../lib/frpc.sh"
|
|
# shellcheck source=../lib/manage.sh
|
|
source "$BATS_TEST_DIRNAME/../lib/manage.sh"
|
|
|
|
# A church with Accounts and Events, and the products' hooks recording what they'd do.
|
|
export CROSSCODE_HOME="$TMP/home"
|
|
mkdir -p "$CROSSCODE_HOME/products" "$TMP/sites/hope/accounts" "$TMP/sites/hope/events"
|
|
for p in accounts events; do
|
|
cat > "$CROSSCODE_HOME/products/$p.sh" <<EOF
|
|
${p}_backup() { echo "backup $p" >> "$CALLS"; }
|
|
${p}_keep() { mkdir -p "\$2"; echo "keep $p" >> "$CALLS"; }
|
|
${p}_pm2_names() { echo "hope-$p-backend hope-$p-frontend"; }
|
|
EOF
|
|
done
|
|
cat > "$TMP/sites/hope/church.env" <<EOF
|
|
CHURCH=hope
|
|
PRODUCTS="accounts events"
|
|
ADDRESS=hope.co.za
|
|
ACCOUNTS_DIR=$TMP/sites/hope/accounts
|
|
ACCOUNTS_DB=hope_accounts
|
|
ACCOUNTS_DOMAIN=accounts.hope.co.za
|
|
ACCOUNTS_USER=cc-hope
|
|
EVENTS_DIR=$TMP/sites/hope/events
|
|
EVENTS_DB=hope_events
|
|
EVENTS_DOMAIN=events.hope.co.za
|
|
EVENTS_USER=cc-hope
|
|
EOF
|
|
run_as() { echo "run $3 $4" >> "$CALLS"; }
|
|
db_drop() { echo "drop $1" >> "$CALLS"; }
|
|
}
|
|
|
|
@test "one product named: only it goes, the church keeps the other" {
|
|
run cmd_uninstall hope events --confirm hope
|
|
[ "$status" -eq 0 ]
|
|
grep -q "backup events" "$CALLS"
|
|
! grep -q "backup accounts" "$CALLS"
|
|
grep -q "drop hope_events" "$CALLS"
|
|
! grep -q "drop hope_accounts" "$CALLS"
|
|
[ ! -e "$TMP/sites/hope/events" ]
|
|
[ -d "$TMP/sites/hope/accounts" ]
|
|
grep -q '^PRODUCTS=accounts$' "$TMP/sites/hope/church.env"
|
|
! grep -q '^EVENTS_' "$TMP/sites/hope/church.env"
|
|
grep -q '^ACCOUNTS_DB=hope_accounts$' "$TMP/sites/hope/church.env"
|
|
[[ "$output" == *"which keeps accounts"* ]]
|
|
ls -d "$TMP/sites/.removed"/hope-*/events
|
|
}
|
|
|
|
@test "then the other: the church goes" {
|
|
run cmd_uninstall hope events --confirm hope
|
|
[ "$status" -eq 0 ]
|
|
run cmd_uninstall hope accounts --confirm hope
|
|
[ "$status" -eq 0 ]
|
|
[ ! -e "$TMP/sites/hope" ]
|
|
[[ "$output" == *"Uninstalled hope."* ]]
|
|
}
|
|
|
|
@test "no product named: the whole church, as before" {
|
|
run cmd_uninstall hope --confirm hope
|
|
[ "$status" -eq 0 ]
|
|
grep -q "drop hope_events" "$CALLS"
|
|
grep -q "drop hope_accounts" "$CALLS"
|
|
[ ! -e "$TMP/sites/hope" ]
|
|
}
|
|
|
|
@test "a product the church doesn't have is refused before anything happens" {
|
|
sed -i 's/^PRODUCTS=.*/PRODUCTS=accounts/' "$TMP/sites/hope/church.env"
|
|
run cmd_uninstall hope events --confirm hope
|
|
[ "$status" -eq 1 ]
|
|
[[ "$output" == *"hope has no events"* ]]
|
|
[ ! -s "$CALLS" ]
|
|
run cmd_uninstall hope website2 --confirm hope
|
|
[ "$status" -eq 1 ]
|
|
}
|
|
|
|
@test "purge with a product: only what was kept of it, also while the church is still here" {
|
|
run cmd_uninstall hope events --confirm hope
|
|
[ "$status" -eq 0 ]
|
|
kept="$(ls -d "$TMP/sites/.removed"/hope-*)"
|
|
mkdir -p "$kept/accounts"
|
|
run cmd_purge hope events --confirm hope
|
|
[ "$status" -eq 0 ]
|
|
[ ! -e "$kept/events" ]
|
|
[ -d "$kept/accounts" ]
|
|
# Accounts is still installed: its kept copy isn't purged, nor the whole church.
|
|
run cmd_purge hope accounts --confirm hope
|
|
[ "$status" -eq 1 ]
|
|
run cmd_purge hope --confirm hope
|
|
[ "$status" -eq 1 ]
|
|
}
|