Commit 7deb3506 authored by Daniel Espinosa Ortiz's avatar Daniel Espinosa Ortiz

Merge branch 'wip/ddl-test' into 'master'

PostgreSQL: DDL test for CREATE DATABSE was added

See merge request !81
parents 9efb86c2 a44018f9
Pipeline #52135 failed with stages
in 14 minutes and 3 seconds
......@@ -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 \
......
/* 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();
}
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment