[DBI backend] Change DBI test URLs to environment variables.

From cmake configuration definitions.
This commit is contained in:
John Ralls 2023-09-21 14:32:19 -07:00
parent a2ae43f33b
commit 90b9142096
4 changed files with 21 additions and 9 deletions

View File

@ -95,8 +95,6 @@ if (NOT DEFINED GNC_DBD_DIR)
set(GNC_DBD_DIR $ENV{GNC_DBD_DIR} CACHE PATH "Hint for location of libdbi-drivers.") set(GNC_DBD_DIR $ENV{GNC_DBD_DIR} CACHE PATH "Hint for location of libdbi-drivers.")
endif() endif()
set(PKGLIBDIR ${CMAKE_INSTALL_LIBDIR}/gnucash) set(PKGLIBDIR ${CMAKE_INSTALL_LIBDIR}/gnucash)
set(TEST_MYSQL_URL "" CACHE STRING "MySQL database URL for testing")
set(TEST_PGSQL_URL "" CACHE STRING "PgSQL database URL for testing")
set(DATADIR_BUILD ${CMAKE_BINARY_DIR}/${DATADIRNAME}) set(DATADIR_BUILD ${CMAKE_BINARY_DIR}/${DATADIRNAME})
string(REPLACE ${CMAKE_INSTALL_PREFIX} "" LIBDIR_BUILD ${LIBDIR}) string(REPLACE ${CMAKE_INSTALL_PREFIX} "" LIBDIR_BUILD ${LIBDIR})

View File

@ -32,8 +32,6 @@ if (WITH_SQL AND NOT WIN32)
) )
target_compile_definitions(test-backend-dbi PRIVATE target_compile_definitions(test-backend-dbi PRIVATE
TEST_MYSQL_URL=\"${TEST_MYSQL_URL}\"
TEST_PGSQL_URL=\"${TEST_PGSQL_URL}\"
DBI_TEST_XML_FILENAME=\"${CMAKE_CURRENT_SOURCE_DIR}/test-dbi.xml\" DBI_TEST_XML_FILENAME=\"${CMAKE_CURRENT_SOURCE_DIR}/test-dbi.xml\"
G_LOG_DOMAIN=\"gnc.backend.dbi\" G_LOG_DOMAIN=\"gnc.backend.dbi\"
) )

View File

@ -71,6 +71,9 @@ static dbi_inst dbi_instance = NULL;
static const gchar* suitename = "/backend/dbi"; static const gchar* suitename = "/backend/dbi";
void test_suite_gnc_backend_dbi (void); void test_suite_gnc_backend_dbi (void);
static std::string mysql_url{};
static std::string pgsql_url{};
using StrVec = std::vector<std::string>; using StrVec = std::vector<std::string>;
typedef struct typedef struct
@ -663,16 +666,19 @@ test_suite_gnc_backend_dbi (void)
{ {
drivers.push_back(dbi_driver_get_name (driver)); drivers.push_back(dbi_driver_get_name (driver));
} }
mysql_url.append(getenv("TEST_MYSQL_URL") ? getenv("TEST_MYSQL_URL") : "");
pgsql_url.append(getenv("TEST_PGSQL_URL") ? getenv("TEST_PGSQL_URL") : "");
for (auto name : drivers) for (auto name : drivers)
{ {
if (name == "sqlite3") if (name == "sqlite3")
create_dbi_test_suite ("sqlite3", "sqlite3"); create_dbi_test_suite ("sqlite3", "sqlite3");
if (strlen (TEST_MYSQL_URL) > 0 && name == "mysql") if (!mysql_url.empty() && name == "mysql")
create_dbi_test_suite ("mysql", TEST_MYSQL_URL); create_dbi_test_suite ("mysql", mysql_url.c_str());
if (strlen (TEST_PGSQL_URL) > 0 && name == "pgsql") if (!pgsql_url.empty() && name == "pgsql")
{ {
g_setenv ("PGOPTIONS", "-c client_min_messages=WARNING", FALSE); g_setenv ("PGOPTIONS", "-c client_min_messages=WARNING", FALSE);
create_dbi_test_suite ("postgres", TEST_PGSQL_URL); create_dbi_test_suite ("postgres", pgsql_url.c_str());
} }
} }

View File

@ -31,6 +31,16 @@ extern void test_suite_gnc_backend_dbi ();
#define GNC_LIB_NAME_2 "gncmod-backend-xml" #define GNC_LIB_NAME_2 "gncmod-backend-xml"
#define GNC_LIB_REL_PATH_2 "xml" #define GNC_LIB_REL_PATH_2 "xml"
/* Test the DBI backends. Always tests SQLite3, MySql/MariaDB and
* Postgres require setting environment variables to inform them of
* available databases of the respective types:
*
* TEST_MYSQL_URL="mysql://user:password@host/database-name/"
* TEST_PGSQL_URL="postgres://user:password@host/database-name/"
*
* host must be resolvable by the system's network.
*/
int int
main (int argc, main (int argc,
char* argv[]) char* argv[])