aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/test_common.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2022-11-21 17:08:39 +0100
committerChristian Grothoff <christian@grothoff.org>2022-11-21 17:08:39 +0100
commitd237b33a42048e26f409375af65ec275ae0eb027 (patch)
tree13e65c716a2df41193540f318621d7655962f954 /src/namestore/test_common.c
parent92c6328195c3bed9abbd56625fcab5952869289c (diff)
downloadgnunet-d237b33a42048e26f409375af65ec275ae0eb027.tar.gz
gnunet-d237b33a42048e26f409375af65ec275ae0eb027.zip
modernize namestore postgres plugin, a bit
Diffstat (limited to 'src/namestore/test_common.c')
-rw-r--r--src/namestore/test_common.c46
1 files changed, 33 insertions, 13 deletions
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)
31{ 31{
32 char *database; 32 char *database;
33 char *db_lib_name; 33 char *db_lib_name;
34 char *emsg;
35 struct GNUNET_NAMESTORE_PluginFunctions *db; 34 struct GNUNET_NAMESTORE_PluginFunctions *db;
36 struct GNUNET_CONFIGURATION_Handle *cfg; 35 struct GNUNET_CONFIGURATION_Handle *cfg;
37 36
38 cfg = GNUNET_CONFIGURATION_create (); 37 cfg = GNUNET_CONFIGURATION_create ();
39 if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cfg_name)) 38 if (GNUNET_OK !=
39 GNUNET_CONFIGURATION_load (cfg,
40 cfg_name))
40 { 41 {
41 GNUNET_break (0); 42 GNUNET_break (0);
42 GNUNET_CONFIGURATION_destroy (cfg); 43 GNUNET_CONFIGURATION_destroy (cfg);
43 return GNUNET_SYSERR; 44 return GNUNET_SYSERR;
44 } 45 }
45 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, 46 if (GNUNET_OK !=
46 "namestore", 47 GNUNET_CONFIGURATION_get_value_string (cfg,
47 "database", 48 "namestore",
48 &database)) 49 "database",
50 &database))
49 { 51 {
50 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No database backend configured\n"); 52 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
53 "No database backend configured\n");
51 GNUNET_CONFIGURATION_destroy (cfg); 54 GNUNET_CONFIGURATION_destroy (cfg);
52 return GNUNET_SYSERR; 55 return GNUNET_SYSERR;
53 } 56 }
54 GNUNET_asprintf (&db_lib_name, "libgnunet_plugin_namestore_%s", database); 57 GNUNET_asprintf (&db_lib_name,
58 "libgnunet_plugin_namestore_%s",
59 database);
55 GNUNET_free (database); 60 GNUNET_free (database);
56 db = GNUNET_PLUGIN_load (db_lib_name, (void *) cfg); 61 db = GNUNET_PLUGIN_load (db_lib_name, (void *) cfg);
57 if (NULL != db) 62 if (NULL == db)
63 {
64 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
65 "Failed to load plugin `%s'\n",
66 db_lib_name);
67 }
68 else
58 { 69 {
59 if (GNUNET_OK != db->reset_database (db->cls, &emsg)) 70 if (GNUNET_OK != db->create_tables (db->cls))
60 { 71 {
61 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error resetting database: %s\n", emsg); 72 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
62 GNUNET_free (emsg); 73 "Error creating tables\n");
74 return GNUNET_SYSERR;
75 }
76 if (GNUNET_OK != db->drop_tables (db->cls))
77 {
78 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
79 "Error dropping tables\n");
63 return GNUNET_SYSERR; 80 return GNUNET_SYSERR;
64 } 81 }
65 GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, db)); 82 GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, db));
@@ -71,13 +88,15 @@ TNC_test_plugin (const char *cfg_name)
71 return GNUNET_YES; 88 return GNUNET_YES;
72} 89}
73 90
91
74/** 92/**
75 * General setup logic for starting the tests. Obtains the @a 93 * General setup logic for starting the tests. Obtains the @a
76 * plugin_name and initializes the @a cfg_name. 94 * plugin_name and initializes the @a cfg_name.
77 */ 95 */
78#define SETUP_CFG2(file_template, plugin_name, cfg_name) \ 96#define SETUP_CFG2(file_template, plugin_name, cfg_name) \
79 do \ 97 do \
80 { \ 98 { \
99 GNUNET_log_setup (__FILE__, "WARNING", NULL); \
81 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); \ 100 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); \
82 GNUNET_asprintf (&cfg_name, file_template, plugin_name); \ 101 GNUNET_asprintf (&cfg_name, file_template, plugin_name); \
83 if (! TNC_test_plugin (cfg_name)) \ 102 if (! TNC_test_plugin (cfg_name)) \
@@ -94,6 +113,7 @@ TNC_test_plugin (const char *cfg_name)
94#define SETUP_CFG(plugin_name, cfg_name) \ 113#define SETUP_CFG(plugin_name, cfg_name) \
95 do \ 114 do \
96 { \ 115 { \
116 GNUNET_log_setup (__FILE__, "WARNING", NULL); \
97 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); \ 117 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); \
98 GNUNET_asprintf (&cfg_name, "test_namestore_api_%s.conf", plugin_name); \ 118 GNUNET_asprintf (&cfg_name, "test_namestore_api_%s.conf", plugin_name); \
99 if (! TNC_test_plugin (cfg_name)) \ 119 if (! TNC_test_plugin (cfg_name)) \