]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#92,!13] Created testutils libs for MySQL, PgSQL and CQL.
authorMarcin Siodelski <marcin@isc.org>
Thu, 30 Aug 2018 16:49:35 +0000 (18:49 +0200)
committerMarcin Siodelski <marcin@isc.org>
Mon, 3 Sep 2018 07:31:34 +0000 (03:31 -0400)
35 files changed:
configure.ac
src/bin/dhcp4/tests/Makefile.am
src/bin/dhcp4/tests/dora_unittest.cc
src/bin/dhcp4/tests/host_unittest.cc
src/bin/dhcp4/tests/kea_controller_unittest.cc
src/bin/dhcp6/tests/Makefile.am
src/bin/dhcp6/tests/kea_controller_unittest.cc
src/lib/cql/Makefile.am
src/lib/cql/testutils/Makefile.am [new file with mode: 0644]
src/lib/cql/testutils/cql_schema.cc [new file with mode: 0644]
src/lib/cql/testutils/cql_schema.h [new file with mode: 0644]
src/lib/database/Makefile.am
src/lib/database/testutils/Makefile.am [new file with mode: 0644]
src/lib/database/testutils/schema.cc [moved from src/lib/dhcpsrv/testutils/schema.cc with 96% similarity]
src/lib/database/testutils/schema.h [moved from src/lib/dhcpsrv/testutils/schema.h with 95% similarity]
src/lib/dhcpsrv/tests/Makefile.am
src/lib/dhcpsrv/tests/cfg_db_access_unittest.cc
src/lib/dhcpsrv/tests/host_mgr_unittest.cc
src/lib/dhcpsrv/tests/mysql_host_data_source_unittest.cc
src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc
src/lib/dhcpsrv/tests/pgsql_host_data_source_unittest.cc
src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc
src/lib/dhcpsrv/testutils/Makefile.am
src/lib/dhcpsrv/testutils/cql_schema.h
src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc
src/lib/mysql/Makefile.am
src/lib/mysql/testutils/Makefile.am [new file with mode: 0644]
src/lib/mysql/testutils/mysql_schema.cc [moved from src/lib/dhcpsrv/testutils/mysql_schema.cc with 94% similarity]
src/lib/mysql/testutils/mysql_schema.h [moved from src/lib/dhcpsrv/testutils/mysql_schema.h with 94% similarity]
src/lib/pgsql/Makefile.am
src/lib/pgsql/tests/pgsql_schema.cc [moved from src/lib/dhcpsrv/testutils/pgsql_schema.cc with 93% similarity]
src/lib/pgsql/tests/pgsql_schema.h [moved from src/lib/dhcpsrv/testutils/pgsql_schema.h with 100% similarity]
src/lib/pgsql/testutils/Makefile.am [new file with mode: 0644]
src/lib/pgsql/testutils/pgsql_schema.cc [new file with mode: 0644]
src/lib/pgsql/testutils/pgsql_schema.h [new file with mode: 0644]

index 0dc860ea61a780a55544414a504ceccf756d064a..3d76e5b9f5fbe686d4ead2f25172d0eaae5d3739 100644 (file)
@@ -1536,6 +1536,7 @@ AC_CONFIG_FILES([Makefile
                  src/lib/cryptolink/tests/Makefile
                  src/lib/database/Makefile
                  src/lib/database/tests/Makefile
+                 src/lib/database/testutils/Makefile
                  src/lib/dhcp/Makefile
                  src/lib/dhcp/tests/Makefile
                  src/lib/dhcp_ddns/Makefile
@@ -1573,10 +1574,13 @@ AC_CONFIG_FILES([Makefile
                  src/lib/log/tests/severity_test.sh
                  src/lib/log/tests/tempdir.h
                  src/lib/mysql/Makefile
+                 src/lib/mysql/testutils/Makefile
                  src/lib/pgsql/Makefile
                  src/lib/pgsql/tests/Makefile
+                 src/lib/pgsql/testutils/Makefile
                  src/lib/cql/Makefile
                  src/lib/cql/tests/Makefile
+                 src/lib/cql/testutils/Makefile
                  src/lib/process/Makefile
                  src/lib/process/tests/Makefile
                  src/lib/process/testutils/Makefile
index 9cad3a6986f05f1b9ca786694af71ed93d239bfc..cd6eb792264f4b9ec8c26aa3b32efa50c9d4aa87 100644 (file)
@@ -132,15 +132,19 @@ dhcp4_unittests_LDADD += $(top_builddir)/src/lib/dhcp/libkea-dhcp++.la
 dhcp4_unittests_LDADD += $(top_builddir)/src/lib/dhcp/tests/libdhcptest.la
 
 if HAVE_MYSQL
+dhcp4_unittests_LDADD += $(top_builddir)/src/lib/mysql/testutils/libmysqltest.la
 dhcp4_unittests_LDADD += $(top_builddir)/src/lib/mysql/libkea-mysql.la
 endif
 if HAVE_PGSQL
+dhcp4_unittests_LDADD += $(top_builddir)/src/lib/pgsql/testutils/libpgsqltest.la
 dhcp4_unittests_LDADD += $(top_builddir)/src/lib/pgsql/libkea-pgsql.la
 endif
 if HAVE_CQL
+dhcp4_unittests_LDADD += $(top_builddir)/src/lib/cql/testutils/libcqltest.la
 dhcp4_unittests_LDADD += $(top_builddir)/src/lib/cql/libkea-cql.la
 endif
 
+dhcp4_unittests_LDADD += $(top_builddir)/src/lib/database/testutils/libdatabasetest.la
 dhcp4_unittests_LDADD += $(top_builddir)/src/lib/database/libkea-database.la
 dhcp4_unittests_LDADD += $(top_builddir)/src/lib/asiolink/libkea-asiolink.la
 dhcp4_unittests_LDADD += $(top_builddir)/src/lib/cc/libkea-cc.la
index a4a4243599b699e735aef64adc2d54abb16e6035..a1b705f2c77c5148f0984c19dc8999e72e312cbd 100644 (file)
 #include <dhcpsrv/host.h>
 #include <dhcpsrv/host_mgr.h>
 #include <dhcpsrv/subnet_id.h>
-#include <dhcpsrv/testutils/cql_schema.h>
-#include <dhcpsrv/testutils/mysql_schema.h>
-#include <dhcpsrv/testutils/pgsql_schema.h>
+
+#ifdef HAVE_CQL
+#include <cql/testutils/cql_schema.h>
+#endif
+
+#ifdef HAVE_MYSQL
+#include <mysql/testutils/mysql_schema.h>
+#endif
+
+#ifdef HAVE_PGSQL
+#include <pgsql/testutils/pgsql_schema.h>
+#endif
+
 #include <dhcp4/tests/dhcp4_test_utils.h>
 #include <dhcp4/tests/dhcp4_client.h>
 #include <boost/shared_ptr.hpp>
@@ -24,6 +34,7 @@
 using namespace isc;
 using namespace isc::asiolink;
 using namespace isc::data;
+using namespace isc::db::test;
 using namespace isc::dhcp;
 using namespace isc::dhcp::test;
 
index c8a36018b854ba4c82c5481f3614d63fccae5931..9b1aa6c904738be7d84a5292559541c4396e0640 100644 (file)
@@ -13,9 +13,6 @@
 #include <dhcpsrv/host.h>
 #include <dhcpsrv/host_mgr.h>
 #include <dhcpsrv/subnet_id.h>
-#include <dhcpsrv/testutils/cql_schema.h>
-#include <dhcpsrv/testutils/mysql_schema.h>
-#include <dhcpsrv/testutils/pgsql_schema.h>
 #include <dhcp4/tests/dhcp4_test_utils.h>
 #include <dhcp4/tests/dhcp4_client.h>
 #include <boost/shared_ptr.hpp>
index 5b843fde7e389dd286be01b1fac0c822db0ff00f..2065fa1782d1c4c095140b92544361732d42eb82 100644 (file)
 #include <dhcpsrv/cfgmgr.h>
 #include <dhcpsrv/lease.h>
 #include <dhcpsrv/lease_mgr_factory.h>
-#include <dhcpsrv/testutils/mysql_schema.h>
+
+#ifdef HAVE_MYSQL
+#include <mysql/testutils/mysql_schema.h>
+#endif
+
 #include <log/logger_support.h>
 #include <util/stopwatch.h>
 
@@ -39,6 +43,7 @@ using namespace isc;
 using namespace isc::asiolink;
 using namespace isc::config;
 using namespace isc::data;
+using namespace isc::db::test;
 using namespace isc::dhcp;
 using namespace isc::dhcp::test;
 using namespace isc::hooks;
index 0686764695b096464ac8eb7320321ed48031ab74..d94f5773477134c3e76e892342dcc9ae6a787366 100644 (file)
@@ -132,17 +132,20 @@ dhcp6_unittests_LDADD += $(top_builddir)/src/lib/dhcp/libkea-dhcp++.la
 dhcp6_unittests_LDADD += $(top_builddir)/src/lib/dhcp/tests/libdhcptest.la
 
 if HAVE_MYSQL
+dhcp6_unittests_LDADD += $(top_builddir)/src/lib/mysql/testutils/libmysqltest.la
 dhcp6_unittests_LDADD += $(top_builddir)/src/lib/mysql/libkea-mysql.la
 endif
 if HAVE_PGSQL
+dhcp6_unittests_LDADD += $(top_builddir)/src/lib/pgsql/testutils/libpgsqltest.la
 dhcp6_unittests_LDADD += $(top_builddir)/src/lib/pgsql/libkea-pgsql.la
 endif
 if HAVE_CQL
+dhcp6_unittests_LDADD += $(top_builddir)/src/lib/cql/testutils/libcqltest.la
 dhcp6_unittests_LDADD += $(top_builddir)/src/lib/cql/libkea-cql.la
 endif
 
+dhcp6_unittests_LDADD += $(top_builddir)/src/lib/database/testutils/libdatabasetest.la
 dhcp6_unittests_LDADD += $(top_builddir)/src/lib/database/libkea-database.la
-
 dhcp6_unittests_LDADD += $(top_builddir)/src/lib/asiolink/libkea-asiolink.la
 dhcp6_unittests_LDADD += $(top_builddir)/src/lib/cc/libkea-cc.la
 dhcp6_unittests_LDADD += $(top_builddir)/src/lib/dns/libkea-dns++.la
index 1238fa970cfcdf9a5d9025a82dc5591c05746e88..6f454d135b2749cf87d74cd0bf6436bc862c8397 100644 (file)
 #include <dhcpsrv/cfgmgr.h>
 #include <dhcpsrv/lease.h>
 #include <dhcpsrv/lease_mgr_factory.h>
-#include <dhcpsrv/testutils/mysql_schema.h>
+
+#ifdef HAVE_MYSQL
+#include <mysql/testutils/mysql_schema.h>
+#endif
+
 #include <log/logger_support.h>
 #include <util/stopwatch.h>
 
@@ -36,6 +40,7 @@ using namespace isc;
 using namespace isc::asiolink;
 using namespace isc::config;
 using namespace isc::data;
+using namespace isc::db::test;
 using namespace isc::dhcp;
 using namespace isc::dhcp::test;
 using namespace isc::hooks;
index 28856fd85fd9151534dafc2418fbf537082d2e8d..7d04e4a286d7c4dcbcaa8fe17684fa3f6744c749 100644 (file)
@@ -1,4 +1,4 @@
-SUBDIRS = . tests
+SUBDIRS = . testutils tests
 
 AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
 AM_CPPFLAGS += $(BOOST_INCLUDES) $(CQL_CPPFLAGS)
diff --git a/src/lib/cql/testutils/Makefile.am b/src/lib/cql/testutils/Makefile.am
new file mode 100644 (file)
index 0000000..8108072
--- /dev/null
@@ -0,0 +1,23 @@
+SUBDIRS = .
+
+AM_CPPFLAGS = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib
+AM_CPPFLAGS += -DDATABASE_SCRIPTS_DIR=\"$(abs_top_srcdir)/src/share/database/scripts\"
+AM_CPPFLAGS += $(BOOST_INCLUDES)
+
+AM_CXXFLAGS = $(KEA_CXXFLAGS)
+
+CLEANFILES = *.gcno *.gcda
+
+if HAVE_GTEST
+
+noinst_LTLIBRARIES = libcqltest.la
+
+libcqltest_la_SOURCES = cql_schema.cc cql_schema.h
+
+libcqltest_la_CXXFLAGS = $(AM_CXXFLAGS)
+libcqltest_la_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES) $(CQL_CPPFLAGS)
+libcqltest_la_LDFLAGS  = $(AM_LDFLAGS) $(CQL_LIBS)
+
+libcqltest_la_LIBADD = $(top_builddir)/src/lib/database/testutils/libdatabasetest.la
+
+endif
diff --git a/src/lib/cql/testutils/cql_schema.cc b/src/lib/cql/testutils/cql_schema.cc
new file mode 100644 (file)
index 0000000..0f004d1
--- /dev/null
@@ -0,0 +1,87 @@
+// Copyright (C) 2015-2018 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <cassandra.h>
+
+#include <cql/cql_connection.h>
+#include <dhcpsrv/testutils/cql_schema.h>
+
+#include <stdlib.h>
+
+#include <fstream>
+#include <iostream>
+#include <sstream>
+#include <string>
+
+namespace isc {
+namespace db {
+namespace test {
+
+const char* CQL_VALID_TYPE = "type=cql";
+
+std::string
+validCqlConnectionString() {
+    return (connectionString(CQL_VALID_TYPE, VALID_NAME, VALID_HOST, VALID_USER,
+                             VALID_PASSWORD));
+}
+
+bool
+softWipeEnabled() {
+    const char* const env = getenv("KEA_TEST_CASSANDRA_WIPE");
+    if (env && (std::string(env) == std::string("soft"))) {
+        return (true);
+    }
+
+    return (false);
+}
+
+void
+destroyCqlSchema(bool force_wipe, bool show_err) {
+    if (force_wipe || !softWipeEnabled()) {
+        // Do full wipe
+        runCqlScript(DATABASE_SCRIPTS_DIR, "cql/dhcpdb_drop.cql", show_err);
+    } else {
+        // do soft wipe (just remove the data, not the structures)
+        runCqlScript(DATABASE_SCRIPTS_DIR, "cql/soft_wipe.cql", show_err);
+    }
+}
+
+void
+createCqlSchema(bool force_wipe, bool show_err) {
+    if (force_wipe || !softWipeEnabled()) {
+        runCqlScript(DATABASE_SCRIPTS_DIR, "cql/dhcpdb_create.cql", show_err);
+    }
+}
+
+void
+runCqlScript(const std::string& path,
+             const std::string& script_name,
+             bool show_err) {
+    std::ostringstream cmd;
+    cmd << "cqlsh -u keatest -p keatest -k keatest";
+    if (!show_err) {
+        cmd << " 2>/dev/null ";
+    }
+
+    cmd << " -f";
+
+    if (!path.empty()) {
+        cmd << path << "/";
+    }
+
+    cmd << script_name;
+
+    int32_t retval = ::system(cmd.str().c_str());
+    if (retval) {
+        std::cerr << "runCqlSchema failed:" << cmd.str() << std::endl;
+    }
+}
+
+}  // namespace test
+}  // namespace dhcp
+}  // namespace isc
diff --git a/src/lib/cql/testutils/cql_schema.h b/src/lib/cql/testutils/cql_schema.h
new file mode 100644 (file)
index 0000000..55f93e0
--- /dev/null
@@ -0,0 +1,95 @@
+// Copyright (C) 2015-2018 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef TEST_CQL_SCHEMA_H
+#define TEST_CQL_SCHEMA_H
+
+#include <config.h>
+#include <database/testutils/schema.h>
+#include <string>
+
+namespace isc {
+namespace db {
+namespace test {
+
+extern const char* CQL_VALID_TYPE;
+
+/// Return valid connection string
+///
+/// @return valid CQL connection string.
+std::string validCqlConnectionString();
+
+/// @brief Clear everything from the database
+///
+/// Submits the current schema drop script:
+///
+///  <TEST_ADMIN_SCRIPTS_DIR>/cql/dhcpdb_drop.cql
+///
+/// to the unit test CQL database. If the script fails, the invoking test
+/// will fail. The output of stderr is suppressed unless the parameter,
+/// show_err is true.
+///
+/// @param force_wipe forces wipe of the database, even if
+/// KEA_TEST_CASSANDRA_WIPE is set.
+/// @param show_err flag which governs whether or not stderr is suppressed.
+void destroyCqlSchema(bool force_wipe, bool show_err = false);
+
+/// @brief Create the CQL Schema
+///
+/// Submits the current schema creation script:
+///
+///  <TEST_ADMIN_SCRIPTS_DIR>/cql/dhcpdb_create.cql
+///
+/// to the unit test CQL database. If the script fails, the invoking test
+/// will fail. The output of stderr is suppressed unless the parameter,
+/// show_err is true.
+///
+/// @param force_wipe forces wipe of the database, even if
+/// KEA_TEST_CASSANDRA_WIPE is set.
+/// @param show_err flag which governs whether or not stderr is suppressed.
+void createCqlSchema(bool force_wipe, bool show_err = false);
+
+/// @brief Run a CQL script against the CQL unit test database
+///
+/// Submits the given CQL script to CQL via cqlsh 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 runCqlScript(const std::string& path, const std::string& script_name,
+                    bool show_err);
+
+/// @brief Returns status if the soft-wipe is enabled or not.
+///
+/// In some deployments (In case of Tomek's dev system) Cassandra tests take
+/// a very long time to execute. This was traced back to slow table/indexes
+/// creation/deletion. With full wipe and recreation of all structures, it
+/// took over 60 seconds for each test to execute. To avoid this problem, a
+/// feature called soft-wipe has been implemented. If enabled, it does not
+/// remove the structures, just the data from essential tables. To enable
+/// it set KEA_TEST_CASSANDRA_WIPE environment variable to 'soft'. Make sure
+/// that the database schema is set up properly before running in soft-wipe
+/// mode.
+///
+/// For example to use soft-wipe mode, you can:
+///
+/// $ cqlsh -u keatest -p keatest -k keatest
+///         -f src/share/database/scripts/cql/dhcpdb_create.cql
+/// $ export KEA_TEST_CASSANDRA_WIPE=soft
+/// $ cd src/lib/dhcpsrv
+/// $ make -j9
+/// $ tests/libdhcpsrv_unittests --gtest_filter=CqlLeaseMgrTest.*
+///
+/// @return true if soft-wipe is enabled, false otherwise
+bool softWipeEnabled();
+};
+};
+};
+
+#endif
index 76a083e13ba880d076f6cb4bb3ca6e9cda42219a..b39015f8db86238a0a639d23fc231e8ba4e8fb2e 100644 (file)
@@ -1,4 +1,4 @@
-SUBDIRS = . tests
+SUBDIRS = . testutils tests
 
 AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
 AM_CPPFLAGS += $(BOOST_INCLUDES)
diff --git a/src/lib/database/testutils/Makefile.am b/src/lib/database/testutils/Makefile.am
new file mode 100644 (file)
index 0000000..1a368e8
--- /dev/null
@@ -0,0 +1,19 @@
+SUBDIRS = .
+
+AM_CPPFLAGS = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib
+
+AM_CXXFLAGS = $(KEA_CXXFLAGS)
+
+CLEANFILES = *.gcno *.gcda
+
+if HAVE_GTEST
+
+noinst_LTLIBRARIES = libdatabasetest.la
+
+libdatabasetest_la_SOURCES = schema.cc schema.h
+
+libdatabasetest_la_CXXFLAGS = $(AM_CXXFLAGS)
+libdatabasetest_la_CPPFLAGS = $(AM_CPPFLAGS)
+libdatabasetest_la_LDFLAGS  = $(AM_LDFLAGS)
+
+endif
similarity index 96%
rename from src/lib/dhcpsrv/testutils/schema.cc
rename to src/lib/database/testutils/schema.cc
index b373363dc7e56026edb29db9cf66f1e39b679282..e02b64310fa9048e772fd07803e3097dab6a926c 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2016-2018 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -10,7 +10,7 @@
 using namespace std;
 
 namespace isc {
-namespace dhcp {
+namespace db {
 namespace test {
 
 // Connection strings.
similarity index 95%
rename from src/lib/dhcpsrv/testutils/schema.h
rename to src/lib/database/testutils/schema.h
index 14d04abb6e2b3c89dda7f64fe7f003e1be126e03..86b22b0c2688a8979f27b36a7f97213b373e8fed 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2016-2018 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -12,7 +12,7 @@
 #include <string>
 
 namespace isc {
-namespace dhcp {
+namespace db {
 namespace test {
 
 extern const char* INVALID_TYPE;
index f652a8ee305bb8d392815eca30c635b9f27a14fa..696ebcf6ebfe99eca49895063fd91da826d0eb1d 100644 (file)
@@ -155,6 +155,20 @@ libdhcpsrv_unittests_LDFLAGS  += $(CQL_LIBS)
 endif
 
 libdhcpsrv_unittests_LDADD  = $(top_builddir)/src/lib/dhcpsrv/testutils/libdhcpsrvtest.la
+
+if HAVE_MYSQL
+libdhcpsrv_unittests_LDADD += $(top_builddir)/src/lib/mysql/testutils/libmysqltest.la
+endif
+
+if HAVE_PGSQL
+libdhcpsrv_unittests_LDADD += $(top_builddir)/src/lib/pgsql/testutils/libpgsqltest.la
+endif
+
+if HAVE_CQL
+libdhcpsrv_unittests_LDADD += $(top_builddir)/src/lib/cql/testutils/libcqltest.la
+endif
+
+libdhcpsrv_unittests_LDADD += $(top_builddir)/src/lib/database/testutils/libdatabasetest.la
 libdhcpsrv_unittests_LDADD += $(top_builddir)/src/lib/dhcpsrv/libkea-dhcpsrv.la
 libdhcpsrv_unittests_LDADD += $(top_builddir)/src/lib/eval/libkea-eval.la
 libdhcpsrv_unittests_LDADD += $(top_builddir)/src/lib/dhcp_ddns/libkea-dhcp_ddns.la
index d78bbf0e68be04836f474849bca23a54422b948b..d680dd1de3eb9a497d6a26a4ff142d441789225f 100644 (file)
 #include <dhcpsrv/host_mgr.h>
 #include <dhcpsrv/lease_mgr.h>
 #include <dhcpsrv/lease_mgr_factory.h>
-#include <dhcpsrv/testutils/mysql_schema.h>
+#include <mysql/testutils/mysql_schema.h>
 #include <testutils/test_to_element.h>
 #include <gtest/gtest.h>
 
 using namespace isc;
+using namespace isc::db::test;
 using namespace isc::dhcp;
-using namespace isc::dhcp::test;
 using namespace isc::test;
 
 namespace {
index 0fb3bf51753b34fcabf1b7f04782e81c3b960ebc..46240eed856823273c2c4e26386c66b83b241802 100644 (file)
 #include <dhcpsrv/tests/test_utils.h>
 
 #if defined HAVE_MYSQL
-#include <dhcpsrv/testutils/mysql_schema.h>
+#include <mysql/testutils/mysql_schema.h>
 #endif
 
 #if defined HAVE_PGSQL
-#include <dhcpsrv/testutils/pgsql_schema.h>
+#include <pgsql/testutils/pgsql_schema.h>
 #endif
 
 #if defined HAVE_CQL
@@ -30,7 +30,9 @@
 
 using namespace isc;
 using namespace isc::db;
+using namespace isc::db::test;
 using namespace isc::dhcp;
+using namespace isc::dhcp::test;
 using namespace isc::asiolink;
 
 namespace {
@@ -619,13 +621,13 @@ HostMgrDbLostCallbackTest::testDbLostCallback() {
 
     // Find the most recently opened socket. Our SQL client's socket should
     // be the next one.
-    int last_open_socket = test::findLastSocketFd();
+    int last_open_socket = findLastSocketFd();
 
     // Connect to the host backend.
     ASSERT_NO_THROW(HostMgr::addBackend(validConnectString()));
 
     // Find the SQL client socket.
-    int sql_socket = test::findLastSocketFd();
+    int sql_socket = findLastSocketFd();
     ASSERT_TRUE(sql_socket > last_open_socket);
 
     // Clear the callback invocation marker.
@@ -667,12 +669,12 @@ MySQLHostMgrTest::SetUp() {
     HostMgrTest::SetUp();
 
     // Ensure schema is the correct one.
-    test::destroyMySQLSchema();
-    test::createMySQLSchema();
+    destroyMySQLSchema();
+    createMySQLSchema();
 
     // Connect to the database
     try {
-        HostMgr::addBackend(test::validMySQLConnectionString());
+        HostMgr::addBackend(validMySQLConnectionString());
     } catch (...) {
         std::cerr << "*** ERROR: unable to open database. The test\n"
             "*** environment is broken and must be fixed before\n"
@@ -687,7 +689,7 @@ void
 MySQLHostMgrTest::TearDown() {
     HostMgr::instance().getHostDataSource()->rollback();
     HostMgr::delBackend("mysql");
-    test::destroyMySQLSchema();
+    destroyMySQLSchema();
 }
 
 /// @brief Test fixture class for validating @c HostMgr using
@@ -695,15 +697,15 @@ MySQLHostMgrTest::TearDown() {
 class MySQLHostMgrDbLostCallbackTest : public HostMgrDbLostCallbackTest {
 public:
     virtual void destroySchema() {
-        test::destroyMySQLSchema();
+        destroyMySQLSchema();
     }
 
     virtual void createSchema() {
-        test::createMySQLSchema();
+        createMySQLSchema();
     }
 
     virtual std::string validConnectString() {
-        return (test::validMySQLConnectionString());
+        return (validMySQLConnectionString());
     }
 };
 
@@ -764,12 +766,12 @@ PostgreSQLHostMgrTest::SetUp() {
     HostMgrTest::SetUp();
 
     // Ensure schema is the correct one.
-    test::destroyPgSQLSchema();
-    test::createPgSQLSchema();
+    destroyPgSQLSchema();
+    createPgSQLSchema();
 
     // Connect to the database
     try {
-        HostMgr::addBackend(test::validPgSQLConnectionString());
+        HostMgr::addBackend(validPgSQLConnectionString());
     } catch (...) {
         std::cerr << "*** ERROR: unable to open database. The test\n"
             "*** environment is broken and must be fixed before\n"
@@ -784,7 +786,7 @@ void
 PostgreSQLHostMgrTest::TearDown() {
     HostMgr::instance().getHostDataSource()->rollback();
     HostMgr::delBackend("postgresql");
-    test::destroyPgSQLSchema();
+    destroyPgSQLSchema();
 }
 
 /// @brief Test fixture class for validating @c HostMgr using
@@ -792,15 +794,15 @@ PostgreSQLHostMgrTest::TearDown() {
 class PostgreSQLHostMgrDbLostCallbackTest : public HostMgrDbLostCallbackTest {
 public:
     virtual void destroySchema() {
-        test::destroyPgSQLSchema();
+        destroyPgSQLSchema();
     }
 
     virtual void createSchema() {
-        test::createPgSQLSchema();
+        createPgSQLSchema();
     }
 
     virtual std::string validConnectString() {
-        return (test::validPgSQLConnectionString());
+        return (validPgSQLConnectionString());
     }
 };
 
@@ -859,12 +861,12 @@ CQLHostMgrTest::SetUp() {
     HostMgrTest::SetUp();
 
     // Ensure schema is the correct one.
-    test::destroyCqlSchema(false, true);
-    test::createCqlSchema(false, true);
+    destroyCqlSchema(false, true);
+    createCqlSchema(false, true);
 
     // Connect to the database
     try {
-        HostMgr::addBackend(test::validCqlConnectionString());
+        HostMgr::addBackend(validCqlConnectionString());
     } catch (...) {
         std::cerr << "*** ERROR: unable to open database. The test\n"
             "*** environment is broken and must be fixed before\n"
@@ -879,7 +881,7 @@ void
 CQLHostMgrTest::TearDown() {
     HostMgr::instance().getHostDataSource()->rollback();
     HostMgr::delBackend("cql");
-    test::destroyCqlSchema(false, true);
+    destroyCqlSchema(false, true);
 }
 
 // This test verifies that reservations for a particular client can
index 898d32add3da2389ebc6fdcc464523d20e6f5650..32c0272ec31fbaef9cde57a6f425923b405c2665 100644 (file)
 #include <dhcpsrv/host.h>
 #include <dhcpsrv/mysql_host_data_source.h>
 #include <dhcpsrv/testutils/generic_host_data_source_unittest.h>
-#include <dhcpsrv/testutils/mysql_schema.h>
 #include <dhcpsrv/testutils/host_data_source_utils.h>
 #include <dhcpsrv/host_mgr.h>
 #include <dhcpsrv/host_data_source_factory.h>
 #include <mysql/mysql_connection.h>
+#include <mysql/testutils/mysql_schema.h>
 
 #include <gtest/gtest.h>
 
@@ -29,6 +29,7 @@
 using namespace isc;
 using namespace isc::asiolink;
 using namespace isc::db;
+using namespace isc::db::test;
 using namespace isc::dhcp;
 using namespace isc::dhcp::test;
 using namespace isc::data;
index e2ce91b2a6e6740246ff7f2669924c3632c77fcf..851fbc777a0f1fe412338338e9e164030a87ce81 100644 (file)
@@ -11,9 +11,9 @@
 #include <dhcpsrv/mysql_lease_mgr.h>
 #include <dhcpsrv/tests/test_utils.h>
 #include <dhcpsrv/tests/generic_lease_mgr_unittest.h>
-#include <dhcpsrv/testutils/mysql_schema.h>
 #include <exceptions/exceptions.h>
 #include <mysql/mysql_connection.h>
+#include <mysql/testutils/mysql_schema.h>
 
 #include <gtest/gtest.h>
 
@@ -26,6 +26,7 @@
 using namespace isc;
 using namespace isc::asiolink;
 using namespace isc::db;
+using namespace isc::db::test;
 using namespace isc::dhcp;
 using namespace isc::dhcp::test;
 using namespace std;
@@ -565,15 +566,15 @@ TEST_F(MySqlLeaseMgrTest, DISABLED_wipeLeases6) {
 class MySQLLeaseMgrDbLostCallbackTest : public LeaseMgrDbLostCallbackTest {
 public:
     virtual void destroySchema() {
-        test::destroyMySQLSchema();
+        destroyMySQLSchema();
     }
 
     virtual void createSchema() {
-        test::createMySQLSchema();
+        createMySQLSchema();
     }
 
     virtual std::string validConnectString() {
-        return (test::validMySQLConnectionString());
+        return (validMySQLConnectionString());
     }
 
     virtual std::string invalidConnectString() {
index ef43d53e6b640bf49c3563b7b26c93c34e3e74b5..89bd6db260d369db790bd3b95fa2bbff4dba1039 100644 (file)
 #include <dhcpsrv/host.h>
 #include <dhcpsrv/pgsql_host_data_source.h>
 #include <dhcpsrv/testutils/generic_host_data_source_unittest.h>
-#include <dhcpsrv/testutils/pgsql_schema.h>
 #include <dhcpsrv/testutils/host_data_source_utils.h>
 #include <dhcpsrv/host_mgr.h>
 #include <dhcpsrv/host_data_source_factory.h>
 #include <pgsql/pgsql_connection.h>
+#include <pgsql/testutils/pgsql_schema.h>
 
 #include <gtest/gtest.h>
 
@@ -29,6 +29,7 @@
 using namespace isc;
 using namespace isc::asiolink;
 using namespace isc::db;
+using namespace isc::db::test;
 using namespace isc::dhcp;
 using namespace isc::dhcp::test;
 using namespace isc::data;
index 27ae1e1cbe0c80df4883e6de75e192d84fd0c7f2..2bc544cafdd356b22bc26188f07eaf81c0448780 100644 (file)
@@ -7,13 +7,13 @@
 #include <config.h>
 
 #include <asiolink/io_address.h>
+#include <exceptions/exceptions.h>
 #include <dhcpsrv/lease_mgr_factory.h>
 #include <dhcpsrv/pgsql_lease_mgr.h>
 #include <dhcpsrv/tests/test_utils.h>
 #include <dhcpsrv/tests/generic_lease_mgr_unittest.h>
-#include <dhcpsrv/testutils/pgsql_schema.h>
 #include <pgsql/pgsql_connection.h>
-#include <exceptions/exceptions.h>
+#include <pgsql/testutils/pgsql_schema.h>
 
 #include <gtest/gtest.h>
 
@@ -26,6 +26,7 @@
 using namespace isc;
 using namespace isc::asiolink;
 using namespace isc::db;
+using namespace isc::db::test;
 using namespace isc::dhcp;
 using namespace isc::dhcp::test;
 using namespace std;
@@ -200,15 +201,15 @@ TEST(PgSqlOpenTest, OpenDatabase) {
 class PgSqlLeaseMgrDbLostCallbackTest : public LeaseMgrDbLostCallbackTest {
 public:
     virtual void destroySchema() {
-        test::destroyPgSQLSchema();
+        destroyPgSQLSchema();
     }
 
     virtual void createSchema() {
-        test::createPgSQLSchema();
+        createPgSQLSchema();
     }
 
     virtual std::string validConnectString() {
-        return (test::validPgSQLConnectionString());
+        return (validPgSQLConnectionString());
     }
 
     virtual std::string invalidConnectString() {
index 02f446e2c59038d961d14ca952a6dd682ccb554a..a56e0e6eb021a6eb9c0bd1e5daca5066ce0895f5 100644 (file)
@@ -17,20 +17,8 @@ libdhcpsrvtest_la_SOURCES += dhcp4o6_test_ipc.cc dhcp4o6_test_ipc.h
 libdhcpsrvtest_la_SOURCES += host_data_source_utils.cc host_data_source_utils.h
 libdhcpsrvtest_la_SOURCES += memory_host_data_source.cc memory_host_data_source.h
 libdhcpsrvtest_la_SOURCES += generic_host_data_source_unittest.cc generic_host_data_source_unittest.h
-
-libdhcpsrvtest_la_SOURCES += schema.cc schema.h
 libdhcpsrvtest_la_SOURCES += lease_file_io.cc lease_file_io.h
 
-if HAVE_MYSQL
-libdhcpsrvtest_la_SOURCES += mysql_schema.cc mysql_schema.h
-endif
-if HAVE_PGSQL
-libdhcpsrvtest_la_SOURCES += pgsql_schema.cc pgsql_schema.h
-endif
-if HAVE_CQL
-libdhcpsrvtest_la_SOURCES += cql_schema.cc cql_schema.h
-endif
-
 libdhcpsrvtest_la_CXXFLAGS = $(AM_CXXFLAGS)
 libdhcpsrvtest_la_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
 
index 91377f96dba82b7c0433899710cd2f09de0e6965..d47a3d23c1a0827c34ddca05c350c83213ebce3e 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2015-2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2015-2018 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -8,7 +8,7 @@
 #define TEST_CQL_SCHEMA_H
 
 #include <config.h>
-#include <dhcpsrv/testutils/schema.h>
+#include <database/testutils/schema.h>
 #include <string>
 
 namespace isc {
index e6b797f0c42d40a54e0485027361a405e3adcfe6..ce14d9192f30ab550f9ea25a02cb486328535c29 100644 (file)
@@ -19,7 +19,7 @@
 #include <dhcpsrv/host_data_source_factory.h>
 #include <dhcpsrv/testutils/generic_host_data_source_unittest.h>
 #include <dhcpsrv/testutils/host_data_source_utils.h>
-#include <dhcpsrv/testutils/schema.h>
+#include <database/testutils/schema.h>
 #include <util/buffer.h>
 
 #include <boost/foreach.hpp>
@@ -35,6 +35,7 @@
 using namespace std;
 using namespace isc::asiolink;
 using namespace isc::db;
+using namespace isc::db::test;
 using namespace isc::util;
 using namespace isc::data;
 
index fd2a8336e4e2e33cbe1e904d9fe2ff4faad021c1..8852b7e8134f033de9aa14dc9d848c455a97def4 100644 (file)
@@ -1,4 +1,4 @@
-SUBDIRS = .
+SUBDIRS = . testutils
 
 AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
 AM_CPPFLAGS += $(BOOST_INCLUDES) $(MYSQL_CPPFLAGS)
diff --git a/src/lib/mysql/testutils/Makefile.am b/src/lib/mysql/testutils/Makefile.am
new file mode 100644 (file)
index 0000000..64680e6
--- /dev/null
@@ -0,0 +1,23 @@
+SUBDIRS = .
+
+AM_CPPFLAGS = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib
+AM_CPPFLAGS += -DDATABASE_SCRIPTS_DIR=\"$(abs_top_srcdir)/src/share/database/scripts\"
+AM_CPPFLAGS += $(BOOST_INCLUDES)
+
+AM_CXXFLAGS = $(KEA_CXXFLAGS)
+
+CLEANFILES = *.gcno *.gcda
+
+if HAVE_GTEST
+
+noinst_LTLIBRARIES = libmysqltest.la
+
+libmysqltest_la_SOURCES = mysql_schema.cc mysql_schema.h
+
+libmysqltest_la_CXXFLAGS = $(AM_CXXFLAGS)
+libmysqltest_la_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES) $(MYSQL_CPPFLAGS)
+libmysqltest_la_LDFLAGS  = $(AM_LDFLAGS) $(MYSQL_LIBS)
+
+libmysqltest_la_LIBADD = $(top_builddir)/src/lib/database/testutils/libdatabasetest.la
+
+endif
similarity index 94%
rename from src/lib/dhcpsrv/testutils/mysql_schema.cc
rename to src/lib/mysql/testutils/mysql_schema.cc
index c079218135e266f21d7956f6393a4267bb92ec2c..42bcf0406cfbb4cf56829ba177a1514b19687950 100644 (file)
@@ -7,7 +7,7 @@
 #include <config.h>
 #include <string>
 #include <mysql.h>
-#include <dhcpsrv/testutils/mysql_schema.h>
+#include <mysql/testutils/mysql_schema.h>
 #include <mysql/mysql_connection.h>
 
 #include <fstream>
@@ -18,7 +18,7 @@
 using namespace std;
 
 namespace isc {
-namespace dhcp {
+namespace db {
 namespace test {
 
 const char* MYSQL_VALID_TYPE = "type=mysql";
@@ -58,5 +58,5 @@ void runMySQLScript(const std::string& path, const std::string& script_name,
 }
 
 }  // namespace test
-}  // namespace dhcp
+}  // namespace db
 }  // namespace isc
similarity index 94%
rename from src/lib/dhcpsrv/testutils/mysql_schema.h
rename to src/lib/mysql/testutils/mysql_schema.h
index d0665eb46adac60222e75c4f78d7e2cc23ff0438..ad2202d5a23f7d8bc0a20d82bddbf0191c85d0ba 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2015-2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2015-2018 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -8,11 +8,11 @@
 #define TEST_MYSQL_SCHEMA_H
 
 #include <config.h>
-#include <dhcpsrv/testutils/schema.h>
+#include <database/testutils/schema.h>
 #include <string>
 
 namespace isc {
-namespace dhcp {
+namespace db {
 namespace test {
 
 extern const char* MYSQL_VALID_TYPE;
index d9dc6515b966f02416c6aedfc3e72428b4f1f1dd..3f92c7f53e3448cf48d54be30e40c65ffa9c58a9 100644 (file)
@@ -1,4 +1,4 @@
-SUBDIRS = . tests
+SUBDIRS = . testutils tests
 
 AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
 AM_CPPFLAGS += $(BOOST_INCLUDES) $(PGSQL_CPPFLAGS)
similarity index 93%
rename from src/lib/dhcpsrv/testutils/pgsql_schema.cc
rename to src/lib/pgsql/tests/pgsql_schema.cc
index fc7d1c3d3518d4cf3ff981b6394ceebf77683fe2..fe26c6c88c628fb8fed4684475875a63f05eb26b 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2016-2018 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -6,7 +6,7 @@
 
 #include <config.h>
 #include <string>
-#include <dhcpsrv/testutils/pgsql_schema.h>
+#include <pgsql/testutils/pgsql_schema.h>
 
 #include <libpq-fe.h>
 
diff --git a/src/lib/pgsql/testutils/Makefile.am b/src/lib/pgsql/testutils/Makefile.am
new file mode 100644 (file)
index 0000000..c46de15
--- /dev/null
@@ -0,0 +1,23 @@
+SUBDIRS = .
+
+AM_CPPFLAGS = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib
+AM_CPPFLAGS += -DDATABASE_SCRIPTS_DIR=\"$(abs_top_srcdir)/src/share/database/scripts\"
+AM_CPPFLAGS += $(BOOST_INCLUDES)
+
+AM_CXXFLAGS = $(KEA_CXXFLAGS)
+
+CLEANFILES = *.gcno *.gcda
+
+if HAVE_GTEST
+
+noinst_LTLIBRARIES = libpgsqltest.la
+
+libpgsqltest_la_SOURCES = pgsql_schema.cc pgsql_schema.h
+
+libpgsqltest_la_CXXFLAGS = $(AM_CXXFLAGS)
+libpgsqltest_la_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES) $(PGSQL_CPPFLAGS)
+libpgsqltest_la_LDFLAGS  = $(AM_LDFLAGS) $(PGSQL_LIBS)
+
+libpgsqltest_la_LIBADD = $(top_builddir)/src/lib/database/testutils/libdatabasetest.la
+
+endif
diff --git a/src/lib/pgsql/testutils/pgsql_schema.cc b/src/lib/pgsql/testutils/pgsql_schema.cc
new file mode 100644 (file)
index 0000000..1d4ab1b
--- /dev/null
@@ -0,0 +1,64 @@
+// Copyright (C) 2016-2018 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+#include <string>
+#include <pgsql/testutils/pgsql_schema.h>
+
+#include <libpq-fe.h>
+
+#include <fstream>
+#include <iostream>
+#include <sstream>
+#include <stdlib.h>
+
+using namespace std;
+
+namespace isc {
+namespace db {
+namespace test {
+
+const char* PGSQL_VALID_TYPE = "type=postgresql";
+
+string
+validPgSQLConnectionString() {
+    return (connectionString(PGSQL_VALID_TYPE, VALID_NAME, VALID_HOST,
+                             VALID_USER, VALID_PASSWORD));
+}
+
+void destroyPgSQLSchema(bool show_err) {
+    runPgSQLScript(DATABASE_SCRIPTS_DIR, "pgsql/dhcpdb_drop.pgsql", show_err);
+}
+
+void createPgSQLSchema(bool show_err) {
+    runPgSQLScript(DATABASE_SCRIPTS_DIR, "pgsql/dhcpdb_create.pgsql", show_err);
+}
+
+void runPgSQLScript(const std::string& path, const std::string& script_name,
+                    bool show_err) {
+    std::ostringstream cmd;
+
+    cmd << "export PGPASSWORD=keatest; cat ";
+    if (!path.empty()) {
+        cmd << " < " << path << "/";
+    }
+
+    cmd << script_name
+        << " | psql --set ON_ERROR_STOP=1 -A -t -h localhost -q -U keatest -d keatest";
+
+    if (!show_err) {
+        cmd << " 2>/dev/null ";
+    }
+
+    int retval = ::system(cmd.str().c_str());
+    if (retval) {
+        std::cerr << "runPgSQLSchema failed:" << cmd.str() << std::endl;
+    }
+}
+
+}  // namespace test
+}  // namespace dhcp
+}  // namespace isc
diff --git a/src/lib/pgsql/testutils/pgsql_schema.h b/src/lib/pgsql/testutils/pgsql_schema.h
new file mode 100644 (file)
index 0000000..8f07ceb
--- /dev/null
@@ -0,0 +1,68 @@
+// Copyright (C) 2016-2018 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef TEST_PGSQL_SCHEMA_H
+#define TEST_PGSQL_SCHEMA_H
+
+#include <config.h>
+#include <database/testutils/schema.h>
+#include <string>
+
+namespace isc {
+namespace db {
+namespace test {
+
+extern const char* PGSQL_VALID_TYPE;
+
+/// Return valid connection string
+///
+/// @return valid PgSQL connection string.
+std::string validPgSQLConnectionString();
+
+/// @brief Clear everything from the database
+///
+/// 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.
+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.
+void runPgSQLScript(const std::string& path, const std::string& script_name,
+                    bool show_err);
+
+};
+};
+};
+
+#endif