From d237b33a42048e26f409375af65ec275ae0eb027 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 21 Nov 2022 17:08:39 +0100 Subject: modernize namestore postgres plugin, a bit --- src/namestore/test_common.c | 46 ++++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) (limited to 'src/namestore/test_common.c') diff --git a/src/namestore/test_common.c b/src/namestore/test_common.c index fbcb51399..4f3a3562b 100644 --- a/src/namestore/test_common.c +++ b/src/namestore/test_common.c @@ -31,35 +31,52 @@ TNC_test_plugin (const char *cfg_name) { char *database; char *db_lib_name; - char *emsg; struct GNUNET_NAMESTORE_PluginFunctions *db; struct GNUNET_CONFIGURATION_Handle *cfg; cfg = GNUNET_CONFIGURATION_create (); - if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cfg_name)) + if (GNUNET_OK != + GNUNET_CONFIGURATION_load (cfg, + cfg_name)) { GNUNET_break (0); GNUNET_CONFIGURATION_destroy (cfg); return GNUNET_SYSERR; } - if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, - "namestore", - "database", - &database)) + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_string (cfg, + "namestore", + "database", + &database)) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No database backend configured\n"); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "No database backend configured\n"); GNUNET_CONFIGURATION_destroy (cfg); return GNUNET_SYSERR; } - GNUNET_asprintf (&db_lib_name, "libgnunet_plugin_namestore_%s", database); + GNUNET_asprintf (&db_lib_name, + "libgnunet_plugin_namestore_%s", + database); GNUNET_free (database); db = GNUNET_PLUGIN_load (db_lib_name, (void *) cfg); - if (NULL != db) + if (NULL == db) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to load plugin `%s'\n", + db_lib_name); + } + else { - if (GNUNET_OK != db->reset_database (db->cls, &emsg)) + if (GNUNET_OK != db->create_tables (db->cls)) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error resetting database: %s\n", emsg); - GNUNET_free (emsg); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Error creating tables\n"); + return GNUNET_SYSERR; + } + if (GNUNET_OK != db->drop_tables (db->cls)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Error dropping tables\n"); return GNUNET_SYSERR; } GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, db)); @@ -71,13 +88,15 @@ TNC_test_plugin (const char *cfg_name) return GNUNET_YES; } + /** * General setup logic for starting the tests. Obtains the @a * plugin_name and initializes the @a cfg_name. */ -#define SETUP_CFG2(file_template, plugin_name, cfg_name) \ +#define SETUP_CFG2(file_template, plugin_name, cfg_name) \ do \ { \ + GNUNET_log_setup (__FILE__, "WARNING", NULL); \ plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); \ GNUNET_asprintf (&cfg_name, file_template, plugin_name); \ if (! TNC_test_plugin (cfg_name)) \ @@ -94,6 +113,7 @@ TNC_test_plugin (const char *cfg_name) #define SETUP_CFG(plugin_name, cfg_name) \ do \ { \ + GNUNET_log_setup (__FILE__, "WARNING", NULL); \ plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); \ GNUNET_asprintf (&cfg_name, "test_namestore_api_%s.conf", plugin_name); \ if (! TNC_test_plugin (cfg_name)) \ -- cgit v1.2.3