61 lines
2.5 KiB
Bash
Executable File
61 lines
2.5 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 optional 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
|
|
|
|
set +e
|
|
ONE_ARG_OUTPUT="$("$SCRIPT" 10.11 2>&1)"
|
|
ONE_ARG_STATUS=$?
|
|
set -e
|
|
|
|
[ "$ONE_ARG_STATUS" -eq 1 ] \
|
|
|| fail "install_db.sh with only a version argument should reach the root check (status 1), got $ONE_ARG_STATUS: $ONE_ARG_OUTPUT"
|
|
printf '%s\n' "$ONE_ARG_OUTPUT" | grep -Fq 'Ten skrypt musi zostać uruchomiony jako root' \
|
|
|| fail "install_db.sh with only a version argument should default PORT to 3306 and reach the root check, got: $ONE_ARG_OUTPUT"
|
|
|
|
echo "install_db_cli_test: OK"
|