diff options
author | Thomas Markwalder <tmark@isc.org> | 2016-04-11 21:16:58 +0200 |
---|---|---|
committer | Thomas Markwalder <tmark@isc.org> | 2016-04-11 21:16:58 +0200 |
commit | 5b978dabe14432341999fcb0c48a9f2e3f88ed15 (patch) | |
tree | 789a22d6673c28ba4a8a6ea74364500d419e05b9 /src/lib/dhcpsrv/testutils | |
parent | [4239] MySQL and Postgresql unit tests use production schema create scripts (diff) | |
download | kea-5b978dabe14432341999fcb0c48a9f2e3f88ed15.tar.xz kea-5b978dabe14432341999fcb0c48a9f2e3f88ed15.zip |
[4239] Added drop scripts for both MySQL and Postgresql
Rather than use hard-coded lists or query logic for dropping the
database all MySQL and Posgresql tests use new drop scripts
added to src/bind/admin/scripts.
src/bin/admin/scripts/mysql/dhcpdb_drop.mysql
- New SQL script to drop a MySQL database
src/bin/admin/scripts/pgsql/dhcpdb_drop.pgsql
- New SQL script to drop a Postgresql database
src/bin/admin/tests/mysql_tests.sh.in
- mysql_wipe() - modified to use new drop script
src/bin/admin/tests/pgsql_tests.sh.in
- pgsql_wipe() modified to use new drop script
src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc
- TEST(MySqlOpenTest, OpenDatabase) - added show_err=true
to destroyMySQLSchema() calls
src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc
- TEST(PgSqlOpenTest, OpenDatabase) - added show_err=true
to destroyMySQLSchema() calls
src/lib/dhcpsrv/testutils/mysql_schema.cc
- destroyMySQLSchema(bool show_err) - modified to use the new
drop script and accept show_err parameter
src/lib/dhcpsrv/testutils/pgsql_schema.cc
- destroyPgSQLSchema(bool show_err) - modified to use the new
drop script and accept show_err parameter
Diffstat (limited to 'src/lib/dhcpsrv/testutils')
-rw-r--r-- | src/lib/dhcpsrv/testutils/mysql_schema.cc | 35 | ||||
-rw-r--r-- | src/lib/dhcpsrv/testutils/mysql_schema.h | 59 | ||||
-rw-r--r-- | src/lib/dhcpsrv/testutils/pgsql_schema.cc | 30 | ||||
-rw-r--r-- | src/lib/dhcpsrv/testutils/pgsql_schema.h | 55 |
4 files changed, 69 insertions, 110 deletions
diff --git a/src/lib/dhcpsrv/testutils/mysql_schema.cc b/src/lib/dhcpsrv/testutils/mysql_schema.cc index 7bf2928056..d2376c94b3 100644 --- a/src/lib/dhcpsrv/testutils/mysql_schema.cc +++ b/src/lib/dhcpsrv/testutils/mysql_schema.cc @@ -29,39 +29,8 @@ validMySQLConnectionString() { VALID_USER, VALID_PASSWORD)); } -void destroyMySQLSchema() { - MySqlHolder mysql; - // @todo - replace this with call to drop script once it exists - const char* destroy_statement[] = { - // Turning off referential integrity checks ensures tables get dropped - "SET SESSION FOREIGN_KEY_CHECKS = 0", - "DROP TABLE IF EXISTS lease4", - "DROP TABLE IF EXISTS lease6", - "DROP TABLE IF EXISTS lease6_types", - "DROP TABLE IF EXISTS lease_hwaddr_source", - "DROP TABLE IF EXISTS schema_version", - "DROP TABLE IF EXISTS ipv6_reservations", - "DROP TABLE IF EXISTS hosts", - "DROP TABLE IF EXISTS dhcp4_options", - "DROP TABLE IF EXISTS dhcp6_options", - "DROP TABLE IF EXISTS host_identifier_type", - "DROP TABLE IF EXISTS lease_state", - "DROP TRIGGER IF EXISTS host_BDEL", - "DROP PROCEDURE IF EXISTS lease4DumpHeader", - "DROP PROCEDURE IF EXISTS lease4DumpData", - "DROP PROCEDURE IF EXISTS lease6DumpHeader", - "DROP PROCEDURE IF EXISTS lease6DumpData", - NULL - }; - - // Open database - (void) mysql_real_connect(mysql, "localhost", "keatest", - "keatest", "keatest", 0, NULL, 0); - - // Get rid of everything in it. - for (int i = 0; destroy_statement[i] != NULL; ++i) { - (void) mysql_query(mysql, destroy_statement[i]); - } +void destroyMySQLSchema(bool show_err) { + runMySQLScript(TEST_ADMIN_SCRIPTS_DIR, "mysql/dhcpdb_drop.mysql", show_err); } void createMySQLSchema(bool show_err) { diff --git a/src/lib/dhcpsrv/testutils/mysql_schema.h b/src/lib/dhcpsrv/testutils/mysql_schema.h index e493fdd637..cb95fe2bc9 100644 --- a/src/lib/dhcpsrv/testutils/mysql_schema.h +++ b/src/lib/dhcpsrv/testutils/mysql_schema.h @@ -24,36 +24,43 @@ std::string validMySQLConnectionString(); /// @brief Clear everything from the database /// -/// There is no error checking in this code: if something fails, one of the -/// tests will (should) fall over. -void destroyMySQLSchema(); +/// Submits the current schema drop script: +/// +/// <TEST_ADMIN_SCRIPTS_DIR>/mysql/dhcpdb_drop.mysql +/// +/// to the unit test MySQL database. If the script fails, the invoking test +/// will fail. The output of stderr is suppressed unless the parameter, +/// show_err is true. +/// +/// @param show_err flag which governs whether or not stderr is suppressed. +void destroyMySQLSchema(bool show_err = false); -// @brief Run a MySQL SQL script against the Postgresql unit test database -// -// Submits the given SQL script to MySQL via mysql CLI. The output of -// stderr is suppressed unless the parameter, show_err is true. The is done -// to suppress warnings that might otherwise make test output needlessly -// noisy. A gtest assertion occurs if the script fails to execute. -// -// @param path - path (if not blank) of the script to execute -// @param script_name - file name of the path to execute -// @param show_err flag which governs whether or not stderr is suppressed. +/// @brief Create the MySQL Schema +/// +/// Submits the current schema creation script: +/// +/// <TEST_ADMIN_SCRIPTS_DIR>/mysql/dhcpdb_create.mysql +/// +/// to the unit test MySQL database. If the script fails, the invoking test +/// will fail. The output of stderr is suppressed unless the parameter, +/// show_err is true. +/// +/// @param show_err flag which governs whether or not stderr is suppressed. +void createMySQLSchema(bool show_err = false); + +/// @brief Run a MySQL SQL script against the Postgresql unit test database +/// +/// Submits the given SQL script to MySQL via mysql CLI. The output of +/// stderr is suppressed unless the parameter, show_err is true. The is done +/// to suppress warnings that might otherwise make test output needlessly +/// noisy. A gtest assertion occurs if the script fails to execute. +/// +/// @param path - path (if not blank) of the script to execute +/// @param script_name - file name of the path to execute +/// @param show_err flag which governs whether or not stderr is suppressed. void runMySQLScript(const std::string& path, const std::string& script_name, bool show_err); -// @brief Create the MySQL Schema -// -// Submits the current schema creation script: -// -// <TEST_ADMIN_SCRIPTS_DIR>/mysql/dhcpdb_create.mysql -// -// to the unit test MySQL database. If the script fails, the invoking test -// will fail. The output of stderr is suppressed unless the parameter, -// show_err is true. -// -// @param show_err flag which governs whether or not stderr is suppressed. -void createMySQLSchema(bool show_err = false); - }; }; }; diff --git a/src/lib/dhcpsrv/testutils/pgsql_schema.cc b/src/lib/dhcpsrv/testutils/pgsql_schema.cc index b275d944ef..efa38541fe 100644 --- a/src/lib/dhcpsrv/testutils/pgsql_schema.cc +++ b/src/lib/dhcpsrv/testutils/pgsql_schema.cc @@ -30,33 +30,9 @@ validPgSQLConnectionString() { VALID_USER, VALID_PASSWORD)); } -void destroyPgSQLSchema() { - // @todo - replace this call to run drop script once the script exists - const char* destroy_statement[] = { - "DROP TABLE lease4 CASCADE", - "DROP TABLE LEASE6 CASCADE", - "DROP TABLE lease6_types CASCADE", - "DROP TABLE schema_version CASCADE", - "DROP TABLE lease_state CASCADE", - "DROP FUNCTION lease4DumpHeader()", - "DROP FUNCTION lease4DumpData()", - "DROP FUNCTION lease6DumpHeader()", - "DROP FUNCTION lease6DumpData()", - NULL - }; - - // Open database - PGconn* conn = 0; - conn = PQconnectdb("host = 'localhost' user = 'keatest'" - " password = 'keatest' dbname = 'keatest'"); - - // Get rid of everything in it. - for (int i = 0; destroy_statement[i] != NULL; ++i) { - PGresult* r = PQexec(conn, destroy_statement[i]); - PQclear(r); - } - - PQfinish(conn); +void destroyPgSQLSchema(bool show_err) { + runPgSQLScript(TEST_ADMIN_SCRIPTS_DIR, "pgsql/dhcpdb_drop.pgsql", + show_err); } void createPgSQLSchema(bool show_err) { diff --git a/src/lib/dhcpsrv/testutils/pgsql_schema.h b/src/lib/dhcpsrv/testutils/pgsql_schema.h index a679da163d..7b4cf54ecf 100644 --- a/src/lib/dhcpsrv/testutils/pgsql_schema.h +++ b/src/lib/dhcpsrv/testutils/pgsql_schema.h @@ -24,33 +24,40 @@ std::string validPgSQLConnectionString(); /// @brief Clear everything from the database /// -/// There is no error checking in this code: if something fails, one of the -/// tests will (should) fall over. -void destroyPgSQLSchema(); +/// Submits the current schema drop script: +/// +/// <TEST_ADMIN_SCRIPTS_DIR>/pgsql/dhcpdb_drop.pgsql +/// +/// to the unit test Postgresql database. If the script fails, the invoking +/// test will fail. The output of stderr is suppressed unless the parameter, +/// show_err is true. +/// +/// @param show_err flag which governs whether or not stderr is suppressed. +void destroyPgSQLSchema(bool show_err = false); -// @brief Create the Postgresql Schema -// -// Submits the current schema creation script: -// -// <TEST_ADMIN_SCRIPTS_DIR>/pgsql/dhcpdb_create.pgsql -// -// to the unit test Postgresql database. If the script fails, the invoking -// test will fail. The output of stderr is suppressed unless the parameter, -// show_err is true. -// -// @param show_err flag which governs whether or not stderr is suppressed. +/// @brief Create the Postgresql Schema +/// +/// Submits the current schema creation script: +/// +/// <TEST_ADMIN_SCRIPTS_DIR>/pgsql/dhcpdb_create.pgsql +/// +/// to the unit test Postgresql database. If the script fails, the invoking +/// test will fail. The output of stderr is suppressed unless the parameter, +/// show_err is true. +/// +/// @param show_err flag which governs whether or not stderr is suppressed. void createPgSQLSchema(bool show_err = false); -// @brief Run a PgSQL SQL script against the Postgresql unit test database -// -// Submits the given SQL script to Postgresql via psql CLI. The output of -// stderr is suppressed unless the parameter, show_err is true. The is done -// to suppress warnings that might otherwise make test output needlessly -// noisy. A gtest assertion occurs if the script fails to execute. -// -// @param path - path (if not blank) of the script to execute -// @param script_name - file name of the path to execute -// @param show_err flag which governs whether or not stderr is suppressed. +/// @brief Run a PgSQL SQL script against the Postgresql unit test database +/// +/// Submits the given SQL script to Postgresql via psql CLI. The output of +/// stderr is suppressed unless the parameter, show_err is true. The is done +/// to suppress warnings that might otherwise make test output needlessly +/// noisy. A gtest assertion occurs if the script fails to execute. +/// +/// @param path - path (if not blank) of the script to execute +/// @param script_name - file name of the path to execute +/// @param show_err flag which governs whether or not stderr is suppressed. void runPgSQLScript(const std::string& path, const std::string& script_name, bool show_err); |