Skip to content

Commit

Permalink
[DBI backend] Change DBI test URLs to environment variables.
Browse files Browse the repository at this point in the history
From cmake configuration definitions.
  • Loading branch information
jralls committed Sep 21, 2023
1 parent a2ae43f commit 90b9142
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
endif()
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})
string(REPLACE ${CMAKE_INSTALL_PREFIX} "" LIBDIR_BUILD ${LIBDIR})
Expand Down
2 changes: 0 additions & 2 deletions libgnucash/backend/dbi/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ if (WITH_SQL AND NOT WIN32)
)

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\"
G_LOG_DOMAIN=\"gnc.backend.dbi\"
)
Expand Down
16 changes: 11 additions & 5 deletions libgnucash/backend/dbi/test/test-backend-dbi-basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ static dbi_inst dbi_instance = NULL;
static const gchar* suitename = "/backend/dbi";
void test_suite_gnc_backend_dbi (void);

static std::string mysql_url{};
static std::string pgsql_url{};

using StrVec = std::vector<std::string>;

typedef struct
Expand Down Expand Up @@ -663,19 +666,22 @@ test_suite_gnc_backend_dbi (void)
{
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)
{
if (name == "sqlite3")
create_dbi_test_suite ("sqlite3", "sqlite3");
if (strlen (TEST_MYSQL_URL) > 0 && name == "mysql")
create_dbi_test_suite ("mysql", TEST_MYSQL_URL);
if (strlen (TEST_PGSQL_URL) > 0 && name == "pgsql")
if (!mysql_url.empty() && name == "mysql")
create_dbi_test_suite ("mysql", mysql_url.c_str());
if (!pgsql_url.empty() && name == "pgsql")
{
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());
}
}

GNC_TEST_ADD_FUNC( suitename, "adjust sql options string localtime",
GNC_TEST_ADD_FUNC( suitename, "adjust sql options string localtime",
test_adjust_sql_options_string );
}
10 changes: 10 additions & 0 deletions libgnucash/backend/dbi/test/test-backend-dbi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ extern void test_suite_gnc_backend_dbi ();
#define GNC_LIB_NAME_2 "gncmod-backend-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
main (int argc,
char* argv[])
Expand Down

0 comments on commit 90b9142

Please sign in to comment.