[libgda: 1/2] PostgreSQL: DDL test for CREATE DATABSE was added



commit a44018f9c1f9f7356bc25e1af7dff560e72f27a7
Author: Pavlo Solntsev <p sun fun gmail com>
Date:   Sun Jan 13 20:51:57 2019 -0600

    PostgreSQL: DDL test for CREATE DATABSE was added
    
    DDL test to create database where connection is not needed was added.

 tests/providers/Makefile.am            |  10 +++
 tests/providers/check_postgresql_ddl.c | 129 +++++++++++++++++++++++++++++++++
 tests/providers/meson.build            |  27 ++++++-
 3 files changed, 165 insertions(+), 1 deletion(-)
---
diff --git a/tests/providers/Makefile.am b/tests/providers/Makefile.am
index c5abac389..f3a91c4ed 100644
--- a/tests/providers/Makefile.am
+++ b/tests/providers/Makefile.am
@@ -42,6 +42,9 @@ check_PROGRAMS += check_postgres_meta_partial_1
 TESTS += check_postgres_meta_partial_1
 check_PROGRAMS += check_postgres_meta_partial_2
 TESTS += check_postgres_meta_partial_2
+check_PROGRAMS += check_postgresql_ddl
+TESTS += check_postgresql_ddl
+
 endif
 
 common_sources = \
@@ -115,6 +118,13 @@ check_postgres_meta_partial_2_LDADD =  \
        $(top_builddir)/tests/libgda-test-6.0.la \
        $(COREDEPS_LIBS)
 
+check_postgresql_ddl_SOURCES = $(common_sources) check_postgresql_ddl.c
+check_postgresql_ddl_CFLAGS =
+check_postgresql_ddl_LDADD =  \
+       $(top_builddir)/libgda/libgda-6.0.la \
+       $(top_builddir)/tests/libgda-test-6.0.la \
+       $(COREDEPS_LIBS)
+
 EXTRA_DIST = \
        README \
        gda_check_db.mdb \
diff --git a/tests/providers/check_postgresql_ddl.c b/tests/providers/check_postgresql_ddl.c
new file mode 100644
index 000000000..13e9dd8bb
--- /dev/null
+++ b/tests/providers/check_postgresql_ddl.c
@@ -0,0 +1,129 @@
+/* Test for PostgreSQL provider
+ *
+ * Copyright (C) 2018 Pavlo Solntsev <p sun fun gmail com> 
+ * 
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */ 
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <locale.h>
+#include <libgda/libgda.h>
+
+typedef struct {
+    GdaConnection *cnc;
+    GdaServerProvider *provider;
+    const gchar *cnc_string;
+    gboolean cont;
+    
+}PsqObject;
+
+typedef struct {
+    gchar *username;
+    gchar *password;
+    gboolean encrypt_pass;
+    gboolean can_create_db;
+    gboolean can_create_user;
+} GdaUserInfo;
+
+static void 
+db_create_quark_foreach_func (gchar *name, gchar *value, GdaServerOperation *op)
+{
+       gda_server_operation_set_value_at (op, value, NULL, "/SERVER_CNX_P/%s", name);
+}
+
+static void 
+cnc_create_quark_foreach_func (gchar *name, gchar *value, GdaServerOperation *op)
+{
+       gda_server_operation_set_value_at (op, value, NULL, "/DB_DEF_P/%s", name);
+}
+
+static void
+postgresql_create_db_no_cnc(void)
+{
+  const gchar *db_string = g_getenv("POSTGRESQL_DBCREATE_PARAMS");
+
+  if (!db_string)
+    {
+      g_print ("Please set POSTGRESQL_DBCREATE_PARAMS variable"
+               "with host,user and port (usually 5432)");
+      g_print ("Test will not be performed\n");
+      return;
+    }
+
+  GError *error = NULL;
+
+  GdaServerProvider *provider = NULL;
+
+  provider = gda_config_get_provider ("PostgreSQL",&error);
+
+  if (!provider)
+    {
+      g_print ("%s: Can't get provider\n", G_STRLOC);
+      g_print ("Error: %s\n",error && error->message ? error->message : "No error set");
+    }
+
+  g_assert_nonnull (provider);
+
+  GdaServerOperation *op = gda_server_provider_create_operation (provider,
+                                                                 NULL,
+                                                                 GDA_SERVER_OPERATION_CREATE_DB,
+                                                                 NULL,
+                                                                 &error);
+
+  if (!op)
+    {
+      g_print ("%s: Can't create operation\n", G_STRLOC);
+      g_print ("Error: %s\n",error && error->message ? error->message : "No error set");
+    }
+ 
+  g_assert_nonnull (op); /* We need to terminate the test if op is NULL */ 
+
+/* We need only host name, port and user for DB creation
+ */
+  
+       GdaQuarkList *db_quark_list = NULL;
+  db_quark_list = gda_quark_list_new_from_string (db_string);
+  gda_quark_list_foreach (db_quark_list, (GHFunc) db_create_quark_foreach_func, op);
+
+       gboolean res = gda_server_operation_set_value_at (op, "testddl", NULL, "/DB_DEF_P/DB_NAME");
+
+  g_assert_true (res);
+
+  res = gda_server_provider_perform_operation (provider, NULL, op, &error); 
+ 
+  if (!res)
+    {
+      g_print ("%s: Can't perform operation\n", G_STRLOC);
+      g_print ("Error: %s\n",error && error->message ? error->message : "No error set");
+    }
+ 
+  g_object_unref (op);
+  g_clear_error (&error);
+
+  g_assert_true (res); /* We need to terminate the test if op is NULL */ 
+}
+
+gint
+main (gint   argc,
+      gchar *argv[])
+{
+  setlocale (LC_ALL,"");
+
+  g_test_init (&argc,&argv,NULL);
+
+  g_test_add_func ("/postgresql/create_db_no_cn", postgresql_create_db_no_cnc);
+
+  return g_test_run();
+}
+
diff --git a/tests/providers/meson.build b/tests/providers/meson.build
index e3ef7afb7..2c4480962 100644
--- a/tests/providers/meson.build
+++ b/tests/providers/meson.build
@@ -82,6 +82,31 @@ test('ProviderPostgreSQL', tchkpg,
                ]
        )
 
+tchkpg = executable('check_postgresql_ddl',
+       ['check_postgresql_ddl.c']+providers_common_sources+common_sources+tests_sources,
+       c_args: [
+               '-include',
+               meson.build_root() + '/config.h',
+               '-DCHECK_SQL_FILES="'+meson.source_root()+'"',
+               ],
+       link_with: libgda,
+       dependencies: [
+               libgda_dep,
+               inc_rooth_dep,
+               inc_sqliteh_dep,
+               inc_testsh_dep
+               ],
+       install: false
+       )
+test('ProviderPostgreSQLDDL', tchkpg,
+       timeout: 300,
+       is_parallel: false,
+       env: [
+               'GDA_TOP_SRC_DIR='+meson.source_root(),
+               'GDA_TOP_BUILD_DIR='+meson.build_root()
+               ]
+       )
+
 tchkpg_mu1 = executable('check_postgres_meta_partial_1',
        ['check_postgres_meta_partial-1.c']+providers_common_sources+common_sources+tests_sources,
        c_args: [
@@ -158,4 +183,4 @@ test('ProviderMySQL', tchkmysql,
                'GDA_TOP_BUILD_DIR='+meson.build_root()
                ]
        )
-endif
\ No newline at end of file
+endif


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