[libgda] postgresql: unit tests improvements around server connection
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda] postgresql: unit tests improvements around server connection
- Date: Fri, 11 Jan 2019 16:56:23 +0000 (UTC)
commit 65f1796da2cbd228baeca988e5acb20123f5e3ab
Author: Daniel Espinosa Ortiz <esodan gmail com>
Date: Fri Jan 11 10:55:39 2019 -0600
postgresql: unit tests improvements around server connection
.gitlab-ci.yml | 2 +-
tests/db/Makefile.am | 10 +-
tests/db/check-db-catalog-postgresql.c | 36 +++--
tests/db/meson.build | 14 +-
tests/meta-store/check_meta_store_postgresql.c | 24 ++--
tests/meta-store/common.c | 8 +-
tests/meta-store/common.h | 3 +
tests/providers/check_postgres.c | 178 +++++++++++++-----------
tests/providers/check_postgres_meta_partial-1.c | 11 ++
tests/providers/check_postgres_meta_partial-2.c | 11 ++
tests/providers/prov-test-common.c | 43 +-----
11 files changed, 184 insertions(+), 156 deletions(-)
---
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 24708732f..66819fb75 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -5,7 +5,7 @@
image: ubuntu:devel
services:
- - postgres
+ - postgres:latest
stages:
- build
diff --git a/tests/db/Makefile.am b/tests/db/Makefile.am
index d45d300b5..33be26a1a 100644
--- a/tests/db/Makefile.am
+++ b/tests/db/Makefile.am
@@ -13,8 +13,8 @@ test_programs = \
check_db_column \
check_db_view \
check_db_fkey \
+ check_db_catalog_postgresql \
$(NULL)
-# check_db_catalog_postgresql
check_db_catalog_SOURCES = check-db-catalog.c
check_db_catalog_LDADD = \
@@ -41,10 +41,10 @@ check_db_fkey_LDADD = \
$(top_builddir)/libgda/libgda-6.0.la \
$(COREDEPS_LIBS)
-# check_db_catalog_postgresql_SOURCES = check-db-catalog-postgresql.c
-# check_db_catalog_postgresql_LDADD = \
-# $(top_builddir)/libgda/libgda-6.0.la \
-# $(COREDEPS_LIBS)
+check_db_catalog_postgresql_SOURCES = check-db-catalog-postgresql.c
+check_db_catalog_postgresql_LDADD = \
+ $(top_builddir)/libgda/libgda-6.0.la \
+ $(COREDEPS_LIBS)
include $(top_srcdir)/glib-tap.mk
diff --git a/tests/db/check-db-catalog-postgresql.c b/tests/db/check-db-catalog-postgresql.c
index b55de2f65..dc0d5d63f 100644
--- a/tests/db/check-db-catalog-postgresql.c
+++ b/tests/db/check-db-catalog-postgresql.c
@@ -250,24 +250,42 @@ test_db_catalog_start (CheckDbObject *self,
GError *error = NULL;
gchar **env = g_get_environ ();
- const gchar *cnc_string = g_environ_getenv (env, "POSTGRESQL_CNC_PARAMS");
-
- g_message ("Connecting using: %s", cnc_string);
+ const gchar *cnc_string = g_environ_getenv (env, "POSTGRESQL_META_CNC");
if (cnc_string == NULL) {
- g_message ("Skipping. Error creating connection");
- return;
+ g_print ("Environment variable POSTGRESQL_META_CNC was not set. No PostgreSQL provider test will be
performed \n"
+ "You can set it, for example, to
'DB_NAME=$POSTGRES_DB;HOST=postgres;USERNAME=$POSTGRES_USER;PASSWORD=$POSTGRES_PASSWORD'\n");
+ return;
}
+ g_message ("Connecting using: %s", cnc_string);
+
self->cnc = gda_connection_new_from_string("PostgreSQL",
cnc_string,
NULL,
GDA_CONNECTION_OPTIONS_NONE,
- &error);
+ NULL);
if (self->cnc == NULL) {
- g_message ("Skipping. Error creating connection: %s",
- error && error->message ? error->message : "No error was set");
- return;
+ GdaServerOperation *op;
+ op = gda_server_operation_prepare_create_database ("PostgreSQL", "test", &error);
+ if (op == NULL) {
+ g_message ("Error creating database 'test': %s",
+ error && error->message ? error->message : "No error was set");
+ g_clear_error (&error);
+ return;
+ } else {
+ self->cnc = gda_connection_new_from_string("PostgreSQL",
+ cnc_string,
+ NULL,
+ GDA_CONNECTION_OPTIONS_NONE,
+ &error);
+ if (self->cnc == NULL) {
+ g_message ("Error connecting to created database 'test': %s",
+ error && error->message ? error->message : "No error was set");
+ g_clear_error (&error);
+ return;
+ }
+ }
}
if (!gda_connection_open(self->cnc, &error)) {
diff --git a/tests/db/meson.build b/tests/db/meson.build
index d08a3c932..20011c5d7 100644
--- a/tests/db/meson.build
+++ b/tests/db/meson.build
@@ -170,10 +170,10 @@ tcpg = executable('check-db-catalog-postgresql',
],
install: false
)
-# test('dbcatalog-postgresql', tcpg,
-# timeout: 300,
-# env: [
-# 'GDA_TOP_SRC_DIR='+meson.source_root(),
-# 'GDA_TOP_BUILD_DIR='+meson.build_root()
-# ]
-# )
+test('dbcatalog-postgresql', tcpg,
+ timeout: 300,
+ env: [
+ 'GDA_TOP_SRC_DIR='+meson.source_root(),
+ 'GDA_TOP_BUILD_DIR='+meson.build_root()
+ ]
+ )
diff --git a/tests/meta-store/check_meta_store_postgresql.c b/tests/meta-store/check_meta_store_postgresql.c
index a72b48334..1e728daf4 100644
--- a/tests/meta-store/check_meta_store_postgresql.c
+++ b/tests/meta-store/check_meta_store_postgresql.c
@@ -28,6 +28,7 @@ main(int argc, char ** argv)
GdaMetaStore *store;
gchar *cnc_string = NULL;
GError *error = NULL;
+ gboolean db_created = FALSE;
gda_init ();
@@ -36,22 +37,24 @@ main(int argc, char ** argv)
if (!cnc_string)
{
g_print ("PostgreSQL test not run, please set the POSTGRESQL_META_CNC environment variable \n"
- "For example 'DB_NAME=meta'\n");
+ "For example
'DB_NAME=$POSTGRES_DB;HOST=postgres;USERNAME=$POSTGRES_USER;PASSWORD=$POSTGRES_PASSWORD'\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) {
- if (error) {
- g_print ("Connection no established. Error: %s\n", error->message);
- g_error_free (error);
+ // Try creating the database first
+ test_setup ("PostgreSQL");
+ g_clear_error (&error);
+ cnc = gda_connection_open_from_string ("PostgreSQL", cnc_string, NULL,
GDA_CONNECTION_OPTIONS_NONE, &error);
+ if (cnc == NULL) {
+ g_warning ("Connection no established. Error: %s\n",
+ error && error->message ? error->message : "No error was set");
+ g_clear_error (&error);
+ return EXIT_FAILURE;
}
- g_print ("Postgres test not run, please setup a database 'test', owned by 'test' role with
password 'test1' at localhost\n");
- g_print ("Test Skip.\n");
- return EXIT_FAILURE;
+ db_created = TRUE;
}
- test_finish (cnc);
g_object_unref (cnc);
/* Clean everything which might exist in the store */
gchar *str;
@@ -70,6 +73,9 @@ main(int argc, char ** argv)
/* Tests */
tests_group_1 (store);
g_object_unref (store);
+ if (db_created) {
+ test_finish (cnc);
+ }
g_print ("Test Ok.\n");
diff --git a/tests/meta-store/common.c b/tests/meta-store/common.c
index 9617ce9c6..806a90b88 100644
--- a/tests/meta-store/common.c
+++ b/tests/meta-store/common.c
@@ -731,14 +731,16 @@ test_setup (const gchar *prov_id) {
if (opndb == NULL) {
g_message ("Provider doesn't support database creation: %s",
error && error->message ? error->message : "No error was set");
+ g_clear_error (&error);
} 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;
+ return FALSE;
}
}
+ return TRUE;
}
@@ -761,12 +763,14 @@ test_finish (GdaConnection *cnc) {
if (opndb == NULL) {
g_message ("Provider doesn't support database dropping: %s",
error && error->message ? error->message : "No error was set");
+ g_clear_error (&error);
} 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;
+ return FALSE;
}
}
+ return TRUE;
}
diff --git a/tests/meta-store/common.h b/tests/meta-store/common.h
index 1bfbe1cba..d3072e3df 100644
--- a/tests/meta-store/common.h
+++ b/tests/meta-store/common.h
@@ -46,4 +46,7 @@ void test_parameters (GdaMetaStore *store);
void tests_group_1 (GdaMetaStore *store);
+gboolean test_setup (const gchar *prov_id);
+gboolean test_finish (GdaConnection *cnc);
+
#endif
diff --git a/tests/providers/check_postgres.c b/tests/providers/check_postgres.c
index dc4ce4d3d..069faa219 100644
--- a/tests/providers/check_postgres.c
+++ b/tests/providers/check_postgres.c
@@ -31,19 +31,31 @@ extern GdaConnection *cnc;
extern gboolean params_provided;
extern gboolean fork_tests;
-static int test_timestamp_change_format (void);
+//static int test_timestamp_change_format (void);
int
main (int argc, char **argv)
{
int number_failed = 0;
fork_tests = FALSE;
+ gchar **env;
+ const gchar *cnc_string;
+
+ env = g_get_environ ();
+ cnc_string = g_environ_getenv (env, "POSTGRESQL_DBCREATE_PARAMS");
+ if (cnc_string == NULL) {
+ g_message ("No enviroment variable POSTGRESQL_DBCREATE_PARAMS was set. No PostgreSQL provider
tests will be performed."
+ "Set this environment variable in order to get access to your server. Example:
export
POSTGRESQL_DBCREATE_PARAMS=\"HOST=postgres;ADM_LOGIN=$POSTGRES_USER;ADM_PASSWORD=$POSTGRES_PASSWORD\"");
+ g_strfreev (env);
+ return EXIT_SUCCESS;
+ }
gda_init ();
pinfo = gda_config_get_provider_info (PROVIDER);
if (!pinfo) {
g_warning ("Could not find provider information for %s", PROVIDER);
+ g_strfreev (env);
return EXIT_SUCCESS;
}
g_print ("============= Provider now testing: %s =============\n", pinfo->id);
@@ -68,99 +80,99 @@ main (int argc, char **argv)
number_failed += prov_test_common_clean ();
}
-
+ g_strfreev (env);
g_print ("Test %s\n", (number_failed == 0) ? "Ok" : "failed");
return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}
-static int
-test_timestamp_change_format (void)
-{
- GdaSqlParser *parser = NULL;
- GdaStatement *stmt = NULL;
- GError *error = NULL;
- int number_failed = 0;
- GValue *value = NULL;
+/* static int */
+/* test_timestamp_change_format (void) */
+/* { */
+/* GdaSqlParser *parser = NULL; */
+/* GdaStatement *stmt = NULL; */
+/* GError *error = NULL; */
+/* int number_failed = 0; */
+/* GValue *value = NULL; */
-#ifdef CHECK_EXTRA_INFO
- g_print ("\n============= %s() =============\n", __FUNCTION__);
-#endif
+/* #ifdef CHECK_EXTRA_INFO */
+/* g_print ("\n============= %s() =============\n", __FUNCTION__); */
+/* #endif */
- parser = gda_connection_create_parser (cnc);
- if (!parser)
- parser = gda_sql_parser_new ();
+/* parser = gda_connection_create_parser (cnc); */
+/* if (!parser) */
+/* parser = gda_sql_parser_new (); */
/* change date style */
- stmt = gda_sql_parser_parse_string (parser, "SET datestyle to 'SQL'",
- NULL, &error);
- if (!stmt ||
- (gda_connection_statement_execute_non_select (cnc, stmt, NULL, NULL, &error) == -1)) {
- number_failed ++;
- goto out;
- }
- g_print ("Changed datestyle to SQL\n");
+/* stmt = gda_sql_parser_parse_string (parser, "SET datestyle to 'SQL'", */
+/* NULL, &error); */
+/* if (!stmt || */
+/* (gda_connection_statement_execute_non_select (cnc, stmt, NULL, NULL, &error) == -1)) { */
+/* number_failed ++; */
+/* goto out; */
+/* } */
+/* g_print ("Changed datestyle to SQL\n"); */
/* Check that date format has changed */
- GdaDataHandler *dh;
- gchar *str, *estr;
- GDate *date = NULL;
- dh = gda_server_provider_get_data_handler_g_type (gda_connection_get_provider (cnc), cnc,
G_TYPE_DATE);
- date = g_date_new_dmy (28, G_DATE_SEPTEMBER, 2013);
- g_value_set_boxed ((value = gda_value_new (G_TYPE_DATE)), date);
- g_date_free (date);
- str = gda_data_handler_get_str_from_value (dh, value);
- estr = "09/28/2013";
- if (strcmp (str, estr)) {
- g_set_error (&error, TEST_ERROR, TEST_ERROR_GENERIC,
- "GdaDataHandler converted date to STR in an unexpected way: got '%s' and
expected '%s'", str, estr);
- number_failed ++;
- goto out;
- }
- g_free (str);
-
- str = gda_data_handler_get_sql_from_value (dh, value);
- estr = "'09/28/2013'";
- if (strcmp (str, estr)) {
- g_set_error (&error, TEST_ERROR, TEST_ERROR_GENERIC,
- "GdaDataHandler converted date to SQL in an unexpected way: got '%s' and
expected '%s'", str, estr);
- number_failed ++;
- goto out;
- }
- g_free (str);
+/* GdaDataHandler *dh; */
+/* gchar *str, *estr; */
+/* GDate *date = NULL; */
+/* dh = gda_server_provider_get_data_handler_g_type (gda_connection_get_provider (cnc), cnc,
G_TYPE_DATE); */
+/* date = g_date_new_dmy (28, G_DATE_SEPTEMBER, 2013); */
+/* g_value_set_boxed ((value = gda_value_new (G_TYPE_DATE)), date); */
+/* g_date_free (date); */
+/* str = gda_data_handler_get_str_from_value (dh, value); */
+/* estr = "09/28/2013"; */
+/* if (strcmp (str, estr)) { */
+/* g_set_error (&error, TEST_ERROR, TEST_ERROR_GENERIC, */
+/* "GdaDataHandler converted date to STR in an unexpected way: got '%s' and
expected '%s'", str, estr); */
+/* number_failed ++; */
+/* goto out; */
+/* } */
+/* g_free (str); */
+
+/* str = gda_data_handler_get_sql_from_value (dh, value); */
+/* estr = "'09/28/2013'"; */
+/* if (strcmp (str, estr)) { */
+/* g_set_error (&error, TEST_ERROR, TEST_ERROR_GENERIC, */
+/* "GdaDataHandler converted date to SQL in an unexpected way: got '%s' and
expected '%s'", str, estr); */
+/* number_failed ++; */
+/* goto out; */
+/* } */
+/* g_free (str); */
/* change date style */
- stmt = gda_sql_parser_parse_string (parser, "SET datestyle to 'ISO'",
- NULL, &error);
- if (!stmt ||
- (gda_connection_statement_execute_non_select (cnc, stmt, NULL, NULL, &error) == -1)) {
- number_failed ++;
- goto out;
- }
- g_print ("Changed datestyle to ISO\n");
+/* stmt = gda_sql_parser_parse_string (parser, "SET datestyle to 'ISO'", */
+/* NULL, &error); */
+/* if (!stmt || */
+/* (gda_connection_statement_execute_non_select (cnc, stmt, NULL, NULL, &error) == -1)) { */
+/* number_failed ++; */
+/* goto out; */
+/* } */
+/* g_print ("Changed datestyle to ISO\n"); */
/* Check that date format has changed */
- str = gda_data_handler_get_str_from_value (dh, value);
- estr = "2013-09-28";
- if (strcmp (str, estr)) {
- g_set_error (&error, TEST_ERROR, TEST_ERROR_GENERIC,
- "GdaDataHandler converted date in an unexpected way: got '%s' and expected
'%s'", str, estr);
- number_failed ++;
- goto out;
- }
-out:
- if (value)
- gda_value_free (value);
- if (stmt)
- g_object_unref (stmt);
- g_object_unref (parser);
-
-#ifdef CHECK_EXTRA_INFO
- g_print ("Date format test resulted in %d error(s)\n", number_failed);
- if (number_failed != 0)
- g_print ("error: %s\n", error && error->message ? error->message : "No detail");
- if (error)
- g_error_free (error);
-#endif
-
- return number_failed;
-}
+/* str = gda_data_handler_get_str_from_value (dh, value); */
+/* estr = "2013-09-28"; */
+/* if (strcmp (str, estr)) { */
+/* g_set_error (&error, TEST_ERROR, TEST_ERROR_GENERIC, */
+/* "GdaDataHandler converted date in an unexpected way: got '%s' and expected
'%s'", str, estr); */
+/* number_failed ++; */
+/* goto out; */
+/* } */
+/* out: */
+/* if (value) */
+/* gda_value_free (value); */
+/* if (stmt) */
+/* g_object_unref (stmt); */
+/* g_object_unref (parser); */
+
+/* #ifdef CHECK_EXTRA_INFO */
+/* g_print ("Date format test resulted in %d error(s)\n", number_failed); */
+/* if (number_failed != 0) */
+/* g_print ("error: %s\n", error && error->message ? error->message : "No detail"); */
+/* if (error) */
+/* g_error_free (error); */
+/* #endif */
+
+/* return number_failed; */
+/* } */
diff --git a/tests/providers/check_postgres_meta_partial-1.c b/tests/providers/check_postgres_meta_partial-1.c
index 3dadefbae..f3e7a08d9 100644
--- a/tests/providers/check_postgres_meta_partial-1.c
+++ b/tests/providers/check_postgres_meta_partial-1.c
@@ -35,6 +35,17 @@ main (int argc, char **argv)
{
int number_failed = 0;
fork_tests = FALSE;
+ gchar **env;
+ const gchar *cnc_string;
+
+ env = g_get_environ ();
+ cnc_string = g_environ_getenv (env, "POSTGRESQL_DBCREATE_PARAMS");
+ if (cnc_string == NULL) {
+ g_message ("No enviroment variable POSTGRESQL_DBCREATE_PARAMS was set. No PostgreSQL provider
tests will be performed."
+ "Set this environment variable in order to get access to your server. Example:
export
POSTGRESQL_DBCREATE_PARAMS=\"HOST=postgres;ADM_LOGIN=$POSTGRES_USER;ADM_PASSWORD=$POSTGRES_PASSWORD\"");
+ g_strfreev (env);
+ return EXIT_SUCCESS;
+ }
gda_init ();
diff --git a/tests/providers/check_postgres_meta_partial-2.c b/tests/providers/check_postgres_meta_partial-2.c
index e8ae202fb..770899ef3 100644
--- a/tests/providers/check_postgres_meta_partial-2.c
+++ b/tests/providers/check_postgres_meta_partial-2.c
@@ -35,6 +35,17 @@ main (int argc, char **argv)
{
int number_failed = 0;
fork_tests = FALSE;
+ gchar **env;
+ const gchar *cnc_string;
+
+ env = g_get_environ ();
+ cnc_string = g_environ_getenv (env, "POSTGRESQL_DBCREATE_PARAMS");
+ if (cnc_string == NULL) {
+ g_message ("No enviroment variable POSTGRESQL_DBCREATE_PARAMS was set. No PostgreSQL provider
tests will be performed."
+ "Set this environment variable in order to get access to your server. Example:
export
POSTGRESQL_DBCREATE_PARAMS=\"HOST=postgres;ADM_LOGIN=$POSTGRES_USER;ADM_PASSWORD=$POSTGRES_PASSWORD\"");
+ g_strfreev (env);
+ return EXIT_SUCCESS;
+ }
gda_init ();
diff --git a/tests/providers/prov-test-common.c b/tests/providers/prov-test-common.c
index 5c62cace2..6767adaf7 100644
--- a/tests/providers/prov-test-common.c
+++ b/tests/providers/prov-test-common.c
@@ -47,25 +47,14 @@ prov_test_common_setup (void)
int number_failed = 0;
GError *error = NULL;
GdaServerOperation *opndb;
+ GdaConnection *cnct = NULL;
+ gchar **env = NULL;
+ const gchar *cnc_string = NULL;
#ifdef CHECK_EXTRA_INFO
g_print ("\n============= %s() =============\n", __FUNCTION__);
#endif
- opndb = gda_server_operation_prepare_create_database (pinfo->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, pinfo->id, &error)) {
- g_warning ("Creating database error: %s",
- error && error->message ? error->message : "No error was set");
- g_clear_error (&error);
- return;
- }
- }
-
-
cnc = test_cnc_setup_connection (pinfo->id, "testcheckdb", &error);
if (!cnc) {
if (error) {
@@ -122,37 +111,11 @@ prov_test_common_clean (void)
{
GError *error = NULL;
int number_failed = 0;
- GdaServerOperation *opndb;
- const gchar *prov_id;
#ifdef CHECK_EXTRA_INFO
g_print ("\n============= %s() =============\n", __FUNCTION__);
#endif
- g_message ("Dropping database test...");
-
- 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;
- }
- }
-
-
if (!test_cnc_clean_connection (cnc, &error)) {
g_warning ("Error while cleaning up connection: %s",
error && error->message ? error->message : "No error was set");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]