Files
alt-mysql/tests/install_db_cli_test.sh
T
2026-07-04 15:48:19 +02:00

51 lines
2.0 KiB
Bash
Executable File

#!/bin/bash
set -euo pipefail
PLUGIN_DIR="$(cd "$(dirname "$0")/.." && pwd)"
SCRIPT="$PLUGIN_DIR/scripts/install_db.sh"
fail() {
echo "FAIL: $*" >&2
exit 1
}
[ -x "$SCRIPT" ] || fail "scripts/install_db.sh is missing or not executable"
[ ! -e "$PLUGIN_DIR/scripts/install-alt-mariadb.sh" ] || fail "old install-alt-mariadb.sh still exists"
grep -Fq 'apply_cli_args "$@"' "$SCRIPT" \
|| fail "install_db.sh does not call CLI argument parser"
grep -Fq 'MARIADB_VERSION="$1"' "$SCRIPT" \
|| fail "install_db.sh does not accept MariaDB version as first argument"
grep -Fq 'PORT="$2"' "$SCRIPT" \
|| fail "install_db.sh does not accept port as second argument"
grep -Fq 'MARIADB_DIR="/usr/local/mariadb-$MARIADB_VERSION"' "$SCRIPT" \
|| fail "install_db.sh does not derive MariaDB directory from chosen version"
grep -Fq 'validate_port' "$SCRIPT" \
|| fail "install_db.sh does not validate the chosen port"
grep -Fq 'rerun_plugin_install_if_available' "$SCRIPT" \
|| fail "install_db.sh does not refresh plugin install.sh after DB install"
grep -Fq 'SKIP_PLUGIN_INSTALL_REFRESH' "$SCRIPT" \
|| fail "install_db.sh does not allow explicitly skipping plugin refresh"
grep -Fq '[[ $# -eq 0 ]]' "$SCRIPT" \
|| fail "install_db.sh does not explicitly show usage when called without arguments"
if grep -Fq 'install-alt-mariadb.sh' "$SCRIPT"; then
fail "install_db.sh still references old install-alt-mariadb.sh name"
fi
set +e
NO_ARGS_OUTPUT="$("$SCRIPT" 2>&1)"
NO_ARGS_STATUS=$?
set -e
[ "$NO_ARGS_STATUS" -eq 2 ] || fail "install_db.sh without arguments should exit with status 2, got $NO_ARGS_STATUS"
printf '%s\n' "$NO_ARGS_OUTPUT" | grep -Fq 'Użycie:' \
|| fail "install_db.sh without arguments does not print usage"
printf '%s\n' "$NO_ARGS_OUTPUT" | grep -Fq '<MARIADB_VERSION> <PORT>' \
|| fail "install_db.sh usage does not show required version and port"
if printf '%s\n' "$NO_ARGS_OUTPUT" | grep -Fq 'Ten skrypt musi zostać uruchomiony jako root'; then
fail "install_db.sh without arguments reaches root check instead of usage"
fi
echo "install_db_cli_test: OK"