mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-20 16:15:59 +01:00
Don't attempt to create SQL tables when running tests
Instead, only clear existing tables. The commit assumes that the SQL schemas will be loaded manually before running the test suite, see test/README for the examples.
This commit is contained in:
parent
a202818037
commit
e2b79ea0b6
@ -14,6 +14,7 @@ $ psql template1
|
|||||||
template1=# CREATE USER ejabberd_test WITH PASSWORD 'ejabberd_test';
|
template1=# CREATE USER ejabberd_test WITH PASSWORD 'ejabberd_test';
|
||||||
template1=# CREATE DATABASE ejabberd_test;
|
template1=# CREATE DATABASE ejabberd_test;
|
||||||
template1=# GRANT ALL PRIVILEGES ON DATABASE ejabberd_test TO ejabberd_test;
|
template1=# GRANT ALL PRIVILEGES ON DATABASE ejabberd_test TO ejabberd_test;
|
||||||
|
$ psql ejabberd_test -f sql/pg.sql
|
||||||
|
|
||||||
-------------------
|
-------------------
|
||||||
MySQL
|
MySQL
|
||||||
@ -22,3 +23,4 @@ $ mysql
|
|||||||
mysql> CREATE USER 'ejabberd_test'@'localhost' IDENTIFIED BY 'ejabberd_test';
|
mysql> CREATE USER 'ejabberd_test'@'localhost' IDENTIFIED BY 'ejabberd_test';
|
||||||
mysql> CREATE DATABASE ejabberd_test;
|
mysql> CREATE DATABASE ejabberd_test;
|
||||||
mysql> GRANT ALL ON ejabberd_test.* TO 'ejabberd_test'@'localhost';
|
mysql> GRANT ALL ON ejabberd_test.* TO 'ejabberd_test'@'localhost';
|
||||||
|
$ mysql ejabberd_test < sql/mysql.sql
|
||||||
|
@ -99,7 +99,7 @@ do_init_per_group(mysql, Config) ->
|
|||||||
case catch ejabberd_sql:sql_query(?MYSQL_VHOST, [<<"select 1;">>]) of
|
case catch ejabberd_sql:sql_query(?MYSQL_VHOST, [<<"select 1;">>]) of
|
||||||
{selected, _, _} ->
|
{selected, _, _} ->
|
||||||
mod_muc:shutdown_rooms(?MYSQL_VHOST),
|
mod_muc:shutdown_rooms(?MYSQL_VHOST),
|
||||||
create_sql_tables(mysql, ?config(base_dir, Config)),
|
clear_sql_tables(mysql, ?config(base_dir, Config)),
|
||||||
set_opt(server, ?MYSQL_VHOST, Config);
|
set_opt(server, ?MYSQL_VHOST, Config);
|
||||||
Err ->
|
Err ->
|
||||||
{skip, {mysql_not_available, Err}}
|
{skip, {mysql_not_available, Err}}
|
||||||
@ -108,7 +108,7 @@ do_init_per_group(pgsql, Config) ->
|
|||||||
case catch ejabberd_sql:sql_query(?PGSQL_VHOST, [<<"select 1;">>]) of
|
case catch ejabberd_sql:sql_query(?PGSQL_VHOST, [<<"select 1;">>]) of
|
||||||
{selected, _, _} ->
|
{selected, _, _} ->
|
||||||
mod_muc:shutdown_rooms(?PGSQL_VHOST),
|
mod_muc:shutdown_rooms(?PGSQL_VHOST),
|
||||||
create_sql_tables(pgsql, ?config(base_dir, Config)),
|
clear_sql_tables(pgsql, ?config(base_dir, Config)),
|
||||||
set_opt(server, ?PGSQL_VHOST, Config);
|
set_opt(server, ?PGSQL_VHOST, Config);
|
||||||
Err ->
|
Err ->
|
||||||
{skip, {pgsql_not_available, Err}}
|
{skip, {pgsql_not_available, Err}}
|
||||||
@ -989,9 +989,9 @@ bookmark_conference() ->
|
|||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
%%% SQL stuff
|
%%% SQL stuff
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
create_sql_tables(sqlite, _BaseDir) ->
|
clear_sql_tables(sqlite, _BaseDir) ->
|
||||||
ok;
|
ok;
|
||||||
create_sql_tables(Type, BaseDir) ->
|
clear_sql_tables(Type, BaseDir) ->
|
||||||
{VHost, File} = case Type of
|
{VHost, File} = case Type of
|
||||||
mysql ->
|
mysql ->
|
||||||
Path = case ejabberd_sql:use_new_schema() of
|
Path = case ejabberd_sql:use_new_schema() of
|
||||||
@ -1012,13 +1012,13 @@ create_sql_tables(Type, BaseDir) ->
|
|||||||
end,
|
end,
|
||||||
SQLFile = filename:join([BaseDir, "sql", File]),
|
SQLFile = filename:join([BaseDir, "sql", File]),
|
||||||
CreationQueries = read_sql_queries(SQLFile),
|
CreationQueries = read_sql_queries(SQLFile),
|
||||||
DropTableQueries = drop_table_queries(CreationQueries),
|
ClearTableQueries = clear_table_queries(CreationQueries),
|
||||||
case ejabberd_sql:sql_transaction(
|
case ejabberd_sql:sql_transaction(
|
||||||
VHost, DropTableQueries ++ CreationQueries) of
|
VHost, ClearTableQueries) of
|
||||||
{atomic, ok} ->
|
{atomic, ok} ->
|
||||||
ok;
|
ok;
|
||||||
Err ->
|
Err ->
|
||||||
ct:fail({failed_to_create_sql_tables, Type, Err})
|
ct:fail({failed_to_clear_sql_tables, Type, Err})
|
||||||
end.
|
end.
|
||||||
|
|
||||||
read_sql_queries(File) ->
|
read_sql_queries(File) ->
|
||||||
@ -1029,12 +1029,12 @@ read_sql_queries(File) ->
|
|||||||
ct:fail({open_file_failed, File, Err})
|
ct:fail({open_file_failed, File, Err})
|
||||||
end.
|
end.
|
||||||
|
|
||||||
drop_table_queries(Queries) ->
|
clear_table_queries(Queries) ->
|
||||||
lists:foldl(
|
lists:foldl(
|
||||||
fun(Query, Acc) ->
|
fun(Query, Acc) ->
|
||||||
case split(str:to_lower(Query)) of
|
case split(str:to_lower(Query)) of
|
||||||
[<<"create">>, <<"table">>, Table|_] ->
|
[<<"create">>, <<"table">>, Table|_] ->
|
||||||
[<<"DROP TABLE IF EXISTS ", Table/binary, ";">>|Acc];
|
[<<"DELETE FROM ", Table/binary, ";">>|Acc];
|
||||||
_ ->
|
_ ->
|
||||||
Acc
|
Acc
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user