db tests CI: skip jobs by default; fix pg dump; check client requirements (#1454)
This commit is contained in:
parent
4b9a0c4ef7
commit
d6d9bdd2ec
4 changed files with 38 additions and 24 deletions
7
.github/workflows/ci_tests.yml
vendored
7
.github/workflows/ci_tests.yml
vendored
|
@ -29,7 +29,12 @@ jobs:
|
|||
bats-sqlite:
|
||||
uses: ./.github/workflows/bats-sqlite-coverage.yml
|
||||
|
||||
# Jobs for Postgres and MySQL can have failing tests on GitHub CI, but they
|
||||
# pass when run on devs' machines or in the release checks. We disable them
|
||||
# here by default. Remove the if..false to enable them.
|
||||
|
||||
bats-mariadb:
|
||||
if: ${{ false }}
|
||||
uses: ./.github/workflows/bats-mysql.yml
|
||||
with:
|
||||
database_image: mariadb:latest
|
||||
|
@ -37,6 +42,7 @@ jobs:
|
|||
DATABASE_PASSWORD: ${{ secrets.DATABASE_PASSWORD}}
|
||||
|
||||
bats-mysql:
|
||||
if: ${{ false }}
|
||||
uses: ./.github/workflows/bats-mysql.yml
|
||||
with:
|
||||
database_image: mysql:latest
|
||||
|
@ -44,6 +50,7 @@ jobs:
|
|||
DATABASE_PASSWORD: ${{ secrets.DATABASE_PASSWORD}}
|
||||
|
||||
bats-postgres:
|
||||
if: ${{ false }}
|
||||
uses: ./.github/workflows/bats-postgres.yml
|
||||
secrets:
|
||||
DATABASE_PASSWORD: ${{ secrets.DATABASE_PASSWORD}}
|
||||
|
|
|
@ -19,7 +19,7 @@ about() {
|
|||
die "usage: $script_name [ config_yaml | setup | dump <backup_file> | restore <backup_file> ]"
|
||||
}
|
||||
|
||||
check_mysql_client() {
|
||||
check_requirements() {
|
||||
if ! command -v mysql >/dev/null; then
|
||||
die "missing required program 'mysql' as a mysql client (package mariadb-client-core-10.6 on debian like system)"
|
||||
fi
|
||||
|
@ -41,10 +41,6 @@ exec_sql() {
|
|||
"--password=${MYSQL_PASSWORD}" <<< "$cmd"
|
||||
}
|
||||
|
||||
requirements() {
|
||||
check_mysql_client
|
||||
}
|
||||
|
||||
setup() {
|
||||
exec_sql "DROP DATABASE IF EXISTS crowdsec_test;"
|
||||
exec_sql "CREATE DATABASE crowdsec_test;"
|
||||
|
@ -59,6 +55,7 @@ dump() {
|
|||
if mysqldump --column-statistics 2>&1 | grep -q -v 'unknown option'; then
|
||||
COLUMN_STATISTICS='--column-statistics=0'
|
||||
fi
|
||||
|
||||
silence_password_warning \
|
||||
mysqldump \
|
||||
$COLUMN_STATISTICS \
|
||||
|
@ -99,6 +96,8 @@ config_yaml() {
|
|||
|
||||
[ $# -lt 1 ] && about
|
||||
|
||||
check_requirements
|
||||
|
||||
case "$1" in
|
||||
setup)
|
||||
setup
|
||||
|
|
|
@ -14,8 +14,6 @@ PGHOST=${PGHOST:-127.0.0.1}
|
|||
PGPORT=${PGPORT:-5432}
|
||||
PGPASSWORD=${PGPASSWORD:-postgres}
|
||||
PGUSER=${PGUSER:-postgres}
|
||||
PGDUMP=${PGDUMP:-pg_dumpall}
|
||||
PGRESTORE=${PGRESTORE:-psql}
|
||||
export PGHOST
|
||||
export PGPORT
|
||||
export PGPASSWORD
|
||||
|
@ -25,8 +23,8 @@ about() {
|
|||
die "usage: $script_name [ config_yaml | setup | dump <backup_file> | restore <backup_file> ]"
|
||||
}
|
||||
|
||||
check_postgres_client() {
|
||||
if ! command -v psql --version >/dev/null; then
|
||||
check_requirements() {
|
||||
if ! command -v psql >/dev/null; then
|
||||
die "missing required program 'psql' as a postgres client (package postgres-client-13 on debian like system)"
|
||||
fi
|
||||
}
|
||||
|
@ -36,10 +34,6 @@ exec_sql() {
|
|||
psql <<< "$cmd"
|
||||
}
|
||||
|
||||
requirements() {
|
||||
check_mysql_client
|
||||
}
|
||||
|
||||
setup() {
|
||||
exec_sql "DROP DATABASE IF EXISTS crowdsec_test;"
|
||||
exec_sql "CREATE DATABASE crowdsec_test;"
|
||||
|
@ -50,13 +44,13 @@ setup() {
|
|||
|
||||
dump() {
|
||||
backup_file="${1?Missing file to backup database to}"
|
||||
"${PGDUMP}" > "$backup_file" 2>/dev/null
|
||||
pg_dump -Ft --dbname crowdsec_test --file "$backup_file"
|
||||
}
|
||||
|
||||
restore() {
|
||||
backup_file="${1?missing file to restore database from}"
|
||||
[ -f "$backup_file" ] || die "Backup file $backup_file doesn't exist"
|
||||
"${PGRESTORE}" < "$backup_file" #seems that in some system it needs for two run
|
||||
pg_restore --dbname crowdsec_test --clean "$backup_file"
|
||||
}
|
||||
|
||||
config_yaml() {
|
||||
|
@ -74,6 +68,8 @@ config_yaml() {
|
|||
|
||||
[ $# -lt 1 ] && about
|
||||
|
||||
check_requirements
|
||||
|
||||
case "$1" in
|
||||
setup)
|
||||
setup
|
||||
|
|
|
@ -25,6 +25,23 @@ exec_sql() {
|
|||
sqlite3 "${DB_FILE}" "$@"
|
||||
}
|
||||
|
||||
setup() {
|
||||
:
|
||||
}
|
||||
|
||||
dump() {
|
||||
backup_file="${1?Missing file to backup database to}"
|
||||
# dirty fast cp. nothing should be accessing it right now, anyway.
|
||||
[ -f "${DB_FILE}" ] || die "missing file ${DB_FILE}"
|
||||
cp "${DB_FILE}" "$backup_file"
|
||||
}
|
||||
|
||||
restore() {
|
||||
backup_file="${1?missing file to restore database from}"
|
||||
[ -f "$backup_file" ] || die "Backup file $backup_file doesn't exist"
|
||||
cp "$backup_file" "${DB_FILE}"
|
||||
}
|
||||
|
||||
# you have not removed set -u above, have you?
|
||||
|
||||
[ -z "${CONFIG_YAML-}" ] && die "\$CONFIG_YAML must be defined."
|
||||
|
@ -51,17 +68,12 @@ case "$1" in
|
|||
setup)
|
||||
;;
|
||||
dump)
|
||||
[ $# -lt 2 ] && about
|
||||
backup_file="$2"
|
||||
# dirty fast cp. nothing should be accessing it right now, anyway.
|
||||
[ -f "${DB_FILE}" ] || die "missing file ${DB_FILE}"
|
||||
cp "${DB_FILE}" "$backup_file"
|
||||
shift
|
||||
dump "$@"
|
||||
;;
|
||||
restore)
|
||||
[ $# -lt 2 ] && about
|
||||
backup_file="$2"
|
||||
[ -f "$backup_file" ] || die "missing file $backup_file"
|
||||
cp "$backup_file" "${DB_FILE}"
|
||||
shift
|
||||
restore "$@"
|
||||
;;
|
||||
exec_sql)
|
||||
shift
|
||||
|
|
Loading…
Reference in a new issue