Commit a708f9f2 authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰
Browse files

[3599] version check unit-test implemented.

parent 20c1bcf0
......@@ -1473,6 +1473,7 @@ AC_CONFIG_FILES([compatcheck/Makefile
chmod +x src/bin/dhcp6/tests/dhcp6_process_tests.sh
chmod +x src/bin/keactrl/keactrl
chmod +x src/bin/keactrl/tests/keactrl_tests.sh
chmod +x src/bin/admin/kea-admin
chmod +x src/lib/dns/gen-rdatacode.py
chmod +x src/lib/log/tests/console_test.sh
chmod +x src/lib/log/tests/destination_test.sh
......
......@@ -19,3 +19,7 @@ $(man_MANS):
@echo Man generation disabled. Remove this file, configure with --enable-generate-docs, and rebuild Kea > $@
endif
install-exec-hook:
mkdir -p $(DESTDIR)${datarootdir}/${PACKAGE_NAME}/scripts
install admin-utils.sh $(DESTDIR)${datarootdir}/${PACKAGE_NAME}/scripts
......@@ -32,7 +32,14 @@ db_user="keatest"
db_password="keatest"
db_name="keatest"
. ./admin-utils.sh
# Include utilities. Use installed version if available and
# use build version if it isn't.
if [ -e @datarootdir@/@PACKAGE_NAME@/scripts/admin-utils.sh ]; then
. @datarootdir@/@PACKAGE_NAME@/scripts/admin-utils.sh
else
. @abs_top_builddir@/src/bin/admin/admin-utils.sh
fi
usage() {
printf "kea-admin @PACKAGE_VERSION@\n"
......
......@@ -2,5 +2,8 @@ SUBDIRS = .
EXTRA_DIST = dhcpdb_create.mysql upgrade_1.0_to_2.0.sh
dist_pkgdata_DATA = $(EXTRA_DIR)
install-data-hook:
mkdir -p $(DESTDIR)${datarootdir}/${PACKAGE_NAME}/scripts/mysql
for file in $(EXTRA_DIST); do \
cp $$file $(DESTDIR)${datarootdir}/${PACKAGE_NAME}/scripts/mysql; \
done
......@@ -3,3 +3,9 @@ SUBDIRS = .
EXTRA_DIST = dhcpdb_create.pgsql
dist_pkgdata_DATA = $(EXTRA_DIR)
install-data-hook:
mkdir -p $(DESTDIR)${datarootdir}/${PACKAGE_NAME}/scripts/pgsql
for file in $(EXTRA_DIST); do \
cp $$file $(DESTDIR)${datarootdir}/${PACKAGE_NAME}/scripts/pgsql; \
done
SUBDIRS = .
SHTESTS = memfile_tests.sh
if HAVE_MYSQL
SHTESTS += mysql_tests.sh
endif
if HAVE_PGSQL
SHTESTS += pgsql_tests.sh
endif
noinst_SCRIPTS = $(SHTESTS)
CLEANFILES = *.log
DISTCLEANFILES = memfile_tests.sh mysql_tests.sh
# Execute all test scripts.
check-local:
for shtest in $(SHTESTS) ; do \
echo Running test: $$shtest ; \
chmod +x $(abs_builddir)/$$shtest ; \
${SHELL} $(abs_builddir)/$$shtest || exit ; \
done
......@@ -21,25 +21,62 @@
# directory. If not, include it from the sources.
prefix=@prefix@
if [ -e @datarootdir@/admin-utils.sh ]; then
echo "INCLUDING FROM DESTDIR"
. @datarootdir@/admin-utils.sh
if [ -e @datarootdir@/@PACKAGE_NAME@/scripts/admin-utils.sh ]; then
. @datarootdir@/@PACKAGE_NAME@/scripts/admin-utils.sh
else
echo "INCLUDING FROM BUILDDIR"
. @abs_top_builddir@/src/bin/admin/admin-utils.sh
fi
db_user="keatest"
db_pass="keatest"
db_name="keatest"
# Set location of the kea-admin.
keactrl=@abs_top_builddir@/src/bin/admin/kea-admin
# Wipe all tables from the DB:
mysql_wipe() {
printf "Wiping whole database %s\n" $db_name
mysql -u$db_user -p$db_pass $db_name &>/dev/null <<EOF
SET @tables = NULL;
SELECT GROUP_CONCAT(table_schema, '.', table_name) INTO @tables
FROM information_schema.tables
WHERE table_schema = 'keatest';
SET @tables = CONCAT('DROP TABLE ', @tables);
PREPARE stmt FROM @tables;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
EOF
}
mysql_init_test() {
test_start "mysql.init"
# @todo: Implement this
# Let's wipe the whole database
mysql_wipe
# Ok, now let's create a version 1.7
mysql -u$db_user -p$db_pass $db_name &>/dev/null <<EOF
CREATE TABLE schema_version (
version INT PRIMARY KEY NOT NULL,
minor INT
);
INSERT INTO schema_version VALUES (1, 7);
EOF
version=$(${keactrl} version mysql -u $db_user -p $db_pass -n $db_name)
printf "Reported version: %s, expected 1.7\n" $version
assert_str_eq "1.7" ${version} "Expected kea-admin to return %s, returned value was %s"
test_finish 0
}
mysql_version_test() {
test_start "mysql.version"
# @todo: Implement this
test_finish 0
......@@ -47,7 +84,7 @@ mysql_version_test() {
mysql_upgrade_test() {
test_start "mysql.upgrade"
# @todo: Implement this
test_finish 0
......
......@@ -59,6 +59,23 @@ assert_eq() {
fi
}
# Assertion that checks if two strings are equal.
# If numbers are not equal, the mismatched values are presented and the
# detailed error is printed. The detailed error must use the printf
# formatting like this:
# "Expected that some value 1 %d is equal to some other value %d".
assert_str_eq() {
val1=${1} # Reference value
val2=${2} # Tested value
detailed_err=${3} # Detailed error format string
# If nothing found, present an error an exit.
if [ "${val1}" != "${val2}" ]; then
printf "Assertion failure: ${val1} != ${val2}, for val1=${val1}, val2=${val2}\n"
printf "${detailed_err}\n" ${val1} ${val2}
clean_exit 1
fi
}
# Assertion that checks if one string contains another string.
# If assertion fails, both strings are displayed and the detailed
# error is printed. The detailed error must use the printf formatting
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment