Commit 8be56437 authored by Pavlo Solntsev's avatar Pavlo Solntsev Committed by Daniel Espinosa Ortiz

CI: Fixing PostgreSQL service

* CI file was modified to remove DB definition
* Fixing access of potentially NULL object with a function that doesn't
accept this.
parent 39d91675
...@@ -5,15 +5,14 @@ ...@@ -5,15 +5,14 @@
image: ubuntu:devel image: ubuntu:devel
services: services:
- postgres:latest - postgres
stages: stages:
- build - build
variables: variables:
POSTGRES_DB: test
POSTGRES_USER: test POSTGRES_USER: test
POSTGRES_PASSWORD: "test1" POSTGRES_PASSWORD: test1
DEPENDENCIES: gcc gettext gtk-doc-tools make autoconf DEPENDENCIES: gcc gettext gtk-doc-tools make autoconf
meson ninja-build meson ninja-build
libgtk-3-dev libxml2-dev gnome-common libgtk-3-dev libxml2-dev gnome-common
...@@ -41,8 +40,8 @@ variables: ...@@ -41,8 +40,8 @@ variables:
postgresql-client-common postgresql-client-common
GIT_SUBMODULE_STRATEGY: normal GIT_SUBMODULE_STRATEGY: normal
POSTGRESQL_DBCREATE_PARAMS: "DB_NAME=test;HOST=postgres;USERNAME=test;PASSWORD=test1" POSTGRESQL_DBCREATE_PARAMS: "HOST=postgres;PORT=5432;ADM_LOGIN=test;ADM_PASSWORD='test1'"
POSTGRESQL_CNC_PARAMS: "DB_NAME=test;HOST=postgres;USERNAME=test;PASSWORD=test1" POSTGRESQL_CNC_PARAMS: "HOST=postgres;USERNAME=test;PASSWORD='test1'"
before_script: before_script:
- apt update && apt -y install $DEPENDENCIES - apt update && apt -y install $DEPENDENCIES
...@@ -72,6 +71,8 @@ autotools_build: ...@@ -72,6 +71,8 @@ autotools_build:
meson_build: meson_build:
stage: build stage: build
script: script:
- export PGPASSWORD=$POSTGRES_PASSWORD
- psql -h "postgres" -U "$POSTGRES_USER" -d "$POSTGRES_DB" -c "SELECT 'OK' AS status;"
- meson _build --prefix=/usr -Denable-ci-environment=true - meson _build --prefix=/usr -Denable-ci-environment=true
- cd _build - cd _build
- ninja - ninja
......
...@@ -87,18 +87,13 @@ gda_postgres_render_DROP_DB (GdaServerProvider *provider, GdaConnection *cnc, ...@@ -87,18 +87,13 @@ gda_postgres_render_DROP_DB (GdaServerProvider *provider, GdaConnection *cnc,
{ {
GString *string; GString *string;
gchar *sql = NULL; gchar *sql = NULL;
gchar *tmp; GValue *value = NULL;
string = g_string_new ("DROP DATABASE "); string = g_string_new ("DROP DATABASE ");
tmp = gda_connection_operation_get_sql_identifier_at (cnc, op, "/DB_DESC_P/DB_NAME", error); value = gda_server_operation_get_value_at (op, "/DB_DESC_P/DB_NAME");
if (!tmp) { if (value && G_VALUE_HOLDS (value, G_TYPE_STRING) && g_value_get_string(value))
g_string_free (string, TRUE); g_string_append (string, g_value_get_string (value));
return NULL;
}
g_string_append (string, tmp);
g_free (tmp);
sql = string->str; sql = string->str;
g_string_free (string, FALSE); g_string_free (string, FALSE);
...@@ -428,20 +423,14 @@ gda_postgres_render_DROP_TABLE (GdaServerProvider *provider, GdaConnection *cn ...@@ -428,20 +423,14 @@ gda_postgres_render_DROP_TABLE (GdaServerProvider *provider, GdaConnection *cn
GString *string; GString *string;
const GValue *value; const GValue *value;
gchar *sql = NULL; gchar *sql = NULL;
gchar *tmp;
string = g_string_new ("DROP TABLE "); string = g_string_new ("DROP TABLE IF EXISTS ");
tmp = gda_connection_operation_get_sql_identifier_at (cnc, op, value = gda_server_operation_get_value_at (op, "/TABLE_DESC_P/TABLE_NAME");
"/TABLE_DESC_P/TABLE_NAME", error); if (value && G_VALUE_HOLDS (value, G_TYPE_STRING)) {
if (!tmp) { g_string_append (string, g_value_get_string (value));
g_string_free (string, TRUE);
return NULL;
} }
g_string_append (string, tmp);
g_free (tmp);
value = gda_server_operation_get_value_at (op, "/TABLE_DESC_P/REFERENCED_ACTION"); value = gda_server_operation_get_value_at (op, "/TABLE_DESC_P/REFERENCED_ACTION");
if (value && G_VALUE_HOLDS (value, G_TYPE_STRING)) { if (value && G_VALUE_HOLDS (value, G_TYPE_STRING)) {
g_string_append_c (string, ' '); g_string_append_c (string, ' ');
......
...@@ -33,7 +33,9 @@ typedef struct { ...@@ -33,7 +33,9 @@ typedef struct {
static void create_users_table (CheckDdlObject *self) { static void
create_users_table (CheckDdlObject *self)
{
GError *error = NULL; GError *error = NULL;
gboolean res = FALSE; gboolean res = FALSE;
GdaDdlTable *table = NULL; GdaDdlTable *table = NULL;
...@@ -101,7 +103,9 @@ static void create_users_table (CheckDdlObject *self) { ...@@ -101,7 +103,9 @@ static void create_users_table (CheckDdlObject *self) {
g_assert_true (res); g_assert_true (res);
} }
static void create_companies_table (CheckDdlObject *self) { static void
create_companies_table (CheckDdlObject *self)
{
GError *error = NULL; GError *error = NULL;
gboolean res = FALSE; gboolean res = FALSE;
GdaDdlTable *table = NULL; GdaDdlTable *table = NULL;
...@@ -170,7 +174,8 @@ static void create_companies_table (CheckDdlObject *self) { ...@@ -170,7 +174,8 @@ static void create_companies_table (CheckDdlObject *self) {
} }
static void create_countries_table (CheckDdlObject *self) { static void create_countries_table (CheckDdlObject *self)
{
GError *error = NULL; GError *error = NULL;
gboolean res = FALSE; gboolean res = FALSE;
GdaDdlTable *table = NULL; GdaDdlTable *table = NULL;
...@@ -247,23 +252,26 @@ test_ddl_creator_start (CheckDdlObject *self, ...@@ -247,23 +252,26 @@ test_ddl_creator_start (CheckDdlObject *self,
self->cnc = NULL; self->cnc = NULL;
self->started_db = FALSE; self->started_db = FALSE;
self->cont = FALSE; self->cont = FALSE;
const gchar *cnc_string = NULL;
#ifdef CI_ENVIRONMENT
const gchar *cnc_string = "DB_NAME=test;HOST=postgres;USERNAME=test;PASSWORD=test1"; cnc_string = g_getenv ("POSTGRES_CNC_PARAMS");
#else
const gchar *cnc_string = "DB_NAME=test;HOST=localhost;USERNAME=test;PASSWORD=test1"; if (cnc_string)
#endif {
self->cnc = gda_connection_new_from_string("Postgresql",
self->cnc = gda_connection_new_from_string("Postgresql", cnc_string,
cnc_string, NULL,
NULL, GDA_CONNECTION_OPTIONS_NONE,
GDA_CONNECTION_OPTIONS_NONE, NULL);
NULL); }
if (self->cnc == NULL) { else
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"); g_print ("Postgres test not run\n");
return; g_print ("Please set the variable POSTGRES_CNC_PARAMS with an appropriate user, host, and database\n");
} g_print ("Test Skip.\n");
return;
}
}
g_assert_nonnull (self->cnc); g_assert_nonnull (self->cnc);
...@@ -283,7 +291,7 @@ test_ddl_creator_start (CheckDdlObject *self, ...@@ -283,7 +291,7 @@ test_ddl_creator_start (CheckDdlObject *self,
static void static void
test_ddl_creator_finish (CheckDdlObject *self, test_ddl_creator_finish (CheckDdlObject *self,
gconstpointer user_data) gconstpointer user_data)
{ {
if (self->cnc != NULL) { if (self->cnc != NULL) {
gda_connection_close(self->cnc,NULL); gda_connection_close(self->cnc,NULL);
......
...@@ -133,38 +133,24 @@ test_cnc_open_connection (const gchar *provider, const gchar *dbname, GError **e ...@@ -133,38 +133,24 @@ test_cnc_open_connection (const gchar *provider, const gchar *dbname, GError **e
data.requested_db_name ? data.requested_db_name : dbname); data.requested_db_name ? data.requested_db_name : dbname);
g_print ("Open connection string: %s\n", data.string->str); g_print ("Open connection string: %s\n", data.string->str);
gchar *auth_string = NULL; GString *auth_string = g_string_new ("");
GSList *current = gda_set_get_holders (prov_info->auth_params);
while (current) {
GdaHolder *holder = (GdaHolder *) current->data;
const gchar *id = gda_holder_get_id (holder);
const gchar *env = NULL;
if (g_strrstr (id, "USER") != NULL) {
str = g_strdup_printf ("%s_USER", upname);
env = getenv (str);
g_free (str);
} else if (g_strrstr (id, "PASS") != NULL) {
str = g_strdup_printf ("%s_PASS", upname);
env = getenv (str);
g_free (str);
}
if (env) { const gchar *qlvalue = gda_quark_list_find (cnc_quark_list,"USERNAME");
str = g_strdup_printf ("%s=%s;", id, env);
gchar *tmp = auth_string; if (qlvalue)
auth_string = g_strconcat (auth_string, str, NULL); g_string_append_printf (auth_string,"USERNAME=%s;",qlvalue);
g_free (str);
g_free (tmp); qlvalue = gda_quark_list_find (cnc_quark_list,"PASSWORD");
}
current = g_slist_next (current); if (qlvalue)
} g_string_append_printf (auth_string,"PASSWORD=%s;",qlvalue);
g_message ("Connection string: %s\n",data.string->str);
g_message ("Auth string: %s\n",auth_string->str);
cnc = gda_connection_open_from_string (prov_info->id, data.string->str, auth_string, cnc = gda_connection_open_from_string (prov_info->id, data.string->str, auth_string->str,
GDA_CONNECTION_OPTIONS_NONE, error); GDA_CONNECTION_OPTIONS_NONE, error);
g_free (auth_string); g_string_free (auth_string,TRUE);
g_string_free (data.string, TRUE); g_string_free (data.string, TRUE);
} }
...@@ -226,6 +212,7 @@ test_cnc_setup_connection (const gchar *provider, const gchar *dbname, GError ** ...@@ -226,6 +212,7 @@ test_cnc_setup_connection (const gchar *provider, const gchar *dbname, GError **
str = g_strdup_printf ("%s_DBCREATE_PARAMS", upname); str = g_strdup_printf ("%s_DBCREATE_PARAMS", upname);
db_params = getenv (str); db_params = getenv (str);
g_free (str); g_free (str);
g_message ("Creating database - step\n");
if (db_params) { if (db_params) {
GdaServerOperation *op; GdaServerOperation *op;
...@@ -242,6 +229,7 @@ test_cnc_setup_connection (const gchar *provider, const gchar *dbname, GError ** ...@@ -242,6 +229,7 @@ test_cnc_setup_connection (const gchar *provider, const gchar *dbname, GError **
db_created = TRUE; db_created = TRUE;
} }
g_message ("Opening connection\n");
/* open connection to database */ /* open connection to database */
cnc = test_cnc_open_connection (provider, dbname, error); cnc = test_cnc_open_connection (provider, dbname, error);
......
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