Skip to content

Commit

Permalink
dbcheck-test: add test for dbcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
sebsura authored and BareosBot committed May 29, 2024
1 parent 921de62 commit 49baa84
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 1 deletion.
2 changes: 1 addition & 1 deletion systemtests/scripts/functions
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ run_headless_dbcheck()
{
print_debug "checking with ${BAREOS_DBCHECK_BINARY}"
if test "$debug" -eq 1 ; then
"${BAREOS_DBCHECK_BINARY}" "${working_dir}" "${db_name}" "${db_user}" "${db_password}" --verbose -d 500 "$@" | tee "${tmp}/dbcheck.out"
"${BAREOS_DBCHECK_BINARY}" "${working_dir}" "${db_name}" "${db_user}" "${db_password}" --verbose -b -d 500 "$@" | tee "${tmp}/dbcheck.out"
else
"${BAREOS_DBCHECK_BINARY}" "${working_dir}" "${db_name}" "${db_user}" "${db_password}" -b "$@" >"${tmp}/dbcheck.out" 2>&1
fi
Expand Down
1 change: 1 addition & 0 deletions systemtests/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ add_subdirectory(copy-migrate)
add_subdirectory(copy-archive-job)
add_subdirectory(copy-remote-bscan)
add_subdirectory(dedupestimate)
add_subdirectory(dbcheck)
add_subdirectory(deprecation)
add_subdirectory(droplet-s3)
add_subdirectory(encrypt-signature-no-tls)
Expand Down
21 changes: 21 additions & 0 deletions systemtests/tests/dbcheck/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# BAREOS® - Backup Archiving REcovery Open Sourced
#
# Copyright (C) 2024-2024 Bareos GmbH & Co. KG
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of version three of the GNU Affero General Public
# License as published by the Free Software Foundation and included
# in the file LICENSE.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.

get_filename_component(BASENAME ${CMAKE_CURRENT_BINARY_DIR} NAME)
create_systemtest(${SYSTEMTEST_PREFIX} ${BASENAME})
32 changes: 32 additions & 0 deletions systemtests/tests/dbcheck/test-setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

# BAREOS® - Backup Archiving REcovery Open Sourced
#
# Copyright (C) 2024-2024 Bareos GmbH & Co. KG
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of version three of the GNU Affero General Public
# License as published by the Free Software Foundation and included
# in the file LICENSE.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.

set -e
set -o pipefail
set -u


#shellcheck source=../environment.in
. ./environment

#shellcheck source=../scripts/functions
. "${rscripts}"/functions
"${rscripts}"/cleanup
58 changes: 58 additions & 0 deletions systemtests/tests/dbcheck/testrunner-duplicate-paths
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/bash

# BAREOS® - Backup Archiving REcovery Open Sourced
#
# Copyright (C) 2024-2024 Bareos GmbH & Co. KG
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of version three of the GNU Affero General Public
# License as published by the Free Software Foundation and included
# in the file LICENSE.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.

set -e
set -o pipefail
set -u

#
# Create duplicate path entries and remove them.
#

TestName="$(basename "$(pwd)")"
export TestName

#shellcheck source=../environment.in
. ./environment

#shellcheck source=../scripts/functions
. "${rscripts}"/functions
# recreate the database, so we can start with a clean one
"${rscripts}"/setup

start_test

# we need to get rid of the uniqueness constraint first or we will not be able
# to add duplicate paths
# the easiest way to do this is to drop the index entirely
run_query "DROP INDEX path_name_idx"
run_query "INSERT INTO Path (path) VALUES ('x'), ('y'), ('x')"
run_query "SELECT * FROM Path" > "${tmp}/select_before.out"

run_headless_dbcheck --fix

run_query "SELECT * FROM Path" > "${tmp}/select_after.out"
run_query "WITH counted (path, count) AS (SELECT path, COUNT(*) FROM Path GROUP BY path) SELECT count FROM counted WHERE count > 1" > "${tmp}/after.out"


expect_grep "(0 rows)" "${tmp}/after.out" "Not all duplicates were removed."

end_test

0 comments on commit 49baa84

Please sign in to comment.