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 @@
image: ubuntu:devel
services:
- postgres:latest
- postgres
stages:
- build
- build
variables:
POSTGRES_DB: test
POSTGRES_USER: test
POSTGRES_PASSWORD: "test1"
POSTGRES_PASSWORD: test1
DEPENDENCIES: gcc gettext gtk-doc-tools make autoconf
meson ninja-build
libgtk-3-dev libxml2-dev gnome-common
......@@ -41,8 +40,8 @@ variables:
postgresql-client-common
GIT_SUBMODULE_STRATEGY: normal
POSTGRESQL_DBCREATE_PARAMS: "DB_NAME=test;HOST=postgres;USERNAME=test;PASSWORD=test1"
POSTGRESQL_CNC_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: "HOST=postgres;USERNAME=test;PASSWORD='test1'"
before_script:
- apt update && apt -y install $DEPENDENCIES
......@@ -72,6 +71,8 @@ autotools_build:
meson_build:
stage: build
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
- cd _build
- ninja
......
......@@ -87,18 +87,13 @@ gda_postgres_render_DROP_DB (GdaServerProvider *provider, GdaConnection *cnc,
{
GString *string;
gchar *sql = NULL;
gchar *tmp;
GValue *value = NULL;
string = g_string_new ("DROP DATABASE ");
tmp = gda_connection_operation_get_sql_identifier_at (cnc, op, "/DB_DESC_P/DB_NAME", error);
if (!tmp) {
g_string_free (string, TRUE);
return NULL;
}
g_string_append (string, tmp);
g_free (tmp);
value = gda_server_operation_get_value_at (op, "/DB_DESC_P/DB_NAME");
if (value && G_VALUE_HOLDS (value, G_TYPE_STRING) && g_value_get_string(value))
g_string_append (string, g_value_get_string (value));
sql = string->str;
g_string_free (string, FALSE);
......@@ -428,20 +423,14 @@ gda_postgres_render_DROP_TABLE (GdaServerProvider *provider, GdaConnection *cn
GString *string;
const GValue *value;
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,
"/TABLE_DESC_P/TABLE_NAME", error);
if (!tmp) {
g_string_free (string, TRUE);
return NULL;
value = gda_server_operation_get_value_at (op, "/TABLE_DESC_P/TABLE_NAME");
if (value && G_VALUE_HOLDS (value, G_TYPE_STRING)) {
g_string_append (string, g_value_get_string (value));
}
g_string_append (string, tmp);
g_free (tmp);
value = gda_server_operation_get_value_at (op, "/TABLE_DESC_P/REFERENCED_ACTION");
if (value && G_VALUE_HOLDS (value, G_TYPE_STRING)) {
g_string_append_c (string, ' ');
......
......@@ -33,7 +33,9 @@ typedef struct {
static void create_users_table (CheckDdlObject *self) {
static void
create_users_table (CheckDdlObject *self)
{
GError *error = NULL;
gboolean res = FALSE;
GdaDdlTable *table = NULL;
......@@ -101,7 +103,9 @@ static void create_users_table (CheckDdlObject *self) {
g_assert_true (res);
}
static void create_companies_table (CheckDdlObject *self) {
static void
create_companies_table (CheckDdlObject *self)
{
GError *error = NULL;
gboolean res = FALSE;
GdaDdlTable *table = NULL;
......@@ -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;
gboolean res = FALSE;
GdaDdlTable *table = NULL;
......@@ -247,23 +252,26 @@ test_ddl_creator_start (CheckDdlObject *self,
self->cnc = NULL;
self->started_db = FALSE;
self->cont = FALSE;
#ifdef CI_ENVIRONMENT
const gchar *cnc_string = "DB_NAME=test;HOST=postgres;USERNAME=test;PASSWORD=test1";
#else
const gchar *cnc_string = "DB_NAME=test;HOST=localhost;USERNAME=test;PASSWORD=test1";
#endif
self->cnc = gda_connection_new_from_string("Postgresql",
cnc_string,
NULL,
GDA_CONNECTION_OPTIONS_NONE,
NULL);
if (self->cnc == NULL) {
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;
}
const gchar *cnc_string = NULL;
cnc_string = g_getenv ("POSTGRES_CNC_PARAMS");
if (cnc_string)
{
self->cnc = gda_connection_new_from_string("Postgresql",
cnc_string,
NULL,
GDA_CONNECTION_OPTIONS_NONE,
NULL);
}
else
{
g_print ("Postgres test not run\n");
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);
......@@ -283,7 +291,7 @@ test_ddl_creator_start (CheckDdlObject *self,
static void
test_ddl_creator_finish (CheckDdlObject *self,
gconstpointer user_data)
gconstpointer user_data)
{
if (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
data.requested_db_name ? data.requested_db_name : dbname);
g_print ("Open connection string: %s\n", data.string->str);
gchar *auth_string = NULL;
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);
}
GString *auth_string = g_string_new ("");
if (env) {
str = g_strdup_printf ("%s=%s;", id, env);
const gchar *qlvalue = gda_quark_list_find (cnc_quark_list,"USERNAME");
gchar *tmp = auth_string;
auth_string = g_strconcat (auth_string, str, NULL);
g_free (str);
g_free (tmp);
}
if (qlvalue)
g_string_append_printf (auth_string,"USERNAME=%s;",qlvalue);
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);
g_free (auth_string);
g_string_free (auth_string,TRUE);
g_string_free (data.string, TRUE);
}
......@@ -226,6 +212,7 @@ test_cnc_setup_connection (const gchar *provider, const gchar *dbname, GError **
str = g_strdup_printf ("%s_DBCREATE_PARAMS", upname);
db_params = getenv (str);
g_free (str);
g_message ("Creating database - step\n");
if (db_params) {
GdaServerOperation *op;
......@@ -242,6 +229,7 @@ test_cnc_setup_connection (const gchar *provider, const gchar *dbname, GError **
db_created = TRUE;
}
g_message ("Opening connection\n");
/* open connection to database */
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