#!/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" <> "$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" <> "$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 ] }