[libgda] postgres: fixed meta-store tests



commit 876a797a948423807a4828d5744dba2933a5e5af
Author: Daniel Espinosa Ortiz <esodan gmail com>
Date:   Thu Jan 10 15:58:03 2019 -0600

    postgres: fixed meta-store tests

 tests/meta-store/check_meta_store_postgresql.c | 14 ++++----
 tests/meta-store/common.c                      | 49 ++++++++++++++++++++++++++
 2 files changed, 57 insertions(+), 6 deletions(-)
---
diff --git a/tests/meta-store/check_meta_store_postgresql.c b/tests/meta-store/check_meta_store_postgresql.c
index 7a153f66e..a72b48334 100644
--- a/tests/meta-store/check_meta_store_postgresql.c
+++ b/tests/meta-store/check_meta_store_postgresql.c
@@ -34,11 +34,12 @@ main(int argc, char ** argv)
        /*cnc_string = "DB_NAME=test;HOST=localhost;USERNAME=test;PASSWORD=test1";*/
        cnc_string = getenv ("POSTGRESQL_META_CNC");
        if (!cnc_string)
-    {
-      g_print ("PostgreSQL test not run, please set the POSTGRESQL_META_CNC environment variable \n"
-               "For example 'DB_NAME=meta'\n");
-      return EXIT_FAILURE;
-    }
+       {
+               g_print ("PostgreSQL test not run, please set the POSTGRESQL_META_CNC environment variable \n"
+                               "For example 'DB_NAME=meta'\n");
+               return EXIT_SUCCESS;
+       }
+       test_setup ("PostgreSQL");
        /* connection try */
        cnc = gda_connection_open_from_string ("PostgreSQL", cnc_string, NULL, GDA_CONNECTION_OPTIONS_NONE, 
&error);
        if (cnc == NULL) {
@@ -50,6 +51,7 @@ main(int argc, char ** argv)
                g_print ("Test Skip.\n");
                return EXIT_FAILURE;
        }
+       test_finish (cnc);
        g_object_unref (cnc);
        /* Clean everything which might exist in the store */
        gchar *str;
@@ -70,7 +72,7 @@ main(int argc, char ** argv)
        g_object_unref (store);
 
        g_print ("Test Ok.\n");
-       
+
        return EXIT_SUCCESS;
 }
 
diff --git a/tests/meta-store/common.c b/tests/meta-store/common.c
index 5ce5bf189..9617ce9c6 100644
--- a/tests/meta-store/common.c
+++ b/tests/meta-store/common.c
@@ -721,3 +721,52 @@ test_parameters (GdaMetaStore *store)
        TEST_END (import);
 #undef TNAME
 }
+
+gboolean
+test_setup (const gchar *prov_id) {
+       GError *error = NULL;
+       GdaServerOperation *opndb;
+
+       opndb = gda_server_operation_prepare_create_database (prov_id, "test", &error);
+       if (opndb == NULL) {
+               g_message ("Provider doesn't support database creation: %s",
+                          error && error->message ? error->message : "No error was set");
+       } else {
+               if (!gda_server_operation_perform_create_database (opndb, prov_id, &error)) {
+                       g_warning ("Creating database error: %s",
+                          error && error->message ? error->message : "No error was set");
+                       g_clear_error (&error);
+                       return;
+               }
+       }
+}
+
+
+gboolean
+test_finish (GdaConnection *cnc) {
+       GError *error = NULL;
+       GdaServerOperation *opndb;
+       const gchar *prov_id;
+
+       prov_id = gda_connection_get_provider_name (cnc);
+
+       if (!gda_connection_close (cnc, &error)) {
+               g_warning ("Error clossing connection to database: %s",
+                          error && error->message ? error->message : "No error was set");
+               g_clear_error (&error);
+               return 1;
+       }
+
+       opndb = gda_server_operation_prepare_drop_database (prov_id, "test", &error);
+       if (opndb == NULL) {
+               g_message ("Provider doesn't support database dropping: %s",
+                          error && error->message ? error->message : "No error was set");
+       } else {
+               if (!gda_server_operation_perform_drop_database (opndb, prov_id, &error)) {
+                       g_warning ("Dropping database error: %s",
+                          error && error->message ? error->message : "No error was set");
+                       g_clear_error (&error);
+                       return 1;
+               }
+       }
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]