aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/README2
-rw-r--r--test/ejabberd_SUITE.erl18
2 files changed, 11 insertions, 9 deletions
diff --git a/test/README b/test/README
index 8857cde96..de1a96aa2 100644
--- a/test/README
+++ b/test/README
@@ -14,6 +14,7 @@ $ psql template1
template1=# CREATE USER ejabberd_test WITH PASSWORD 'ejabberd_test';
template1=# CREATE DATABASE ejabberd_test;
template1=# GRANT ALL PRIVILEGES ON DATABASE ejabberd_test TO ejabberd_test;
+$ psql ejabberd_test -f sql/pg.sql
-------------------
MySQL
@@ -22,3 +23,4 @@ $ mysql
mysql> CREATE USER 'ejabberd_test'@'localhost' IDENTIFIED BY 'ejabberd_test';
mysql> CREATE DATABASE ejabberd_test;
mysql> GRANT ALL ON ejabberd_test.* TO 'ejabberd_test'@'localhost';
+$ mysql ejabberd_test < sql/mysql.sql
diff --git a/test/ejabberd_SUITE.erl b/test/ejabberd_SUITE.erl
index e67c6ca40..5739fa780 100644
--- a/test/ejabberd_SUITE.erl
+++ b/test/ejabberd_SUITE.erl
@@ -99,7 +99,7 @@ do_init_per_group(mysql, Config) ->
case catch ejabberd_sql:sql_query(?MYSQL_VHOST, [<<"select 1;">>]) of
{selected, _, _} ->
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);
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
{selected, _, _} ->
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);
Err ->
{skip, {pgsql_not_available, Err}}
@@ -989,9 +989,9 @@ bookmark_conference() ->
%%%===================================================================
%%% SQL stuff
%%%===================================================================
-create_sql_tables(sqlite, _BaseDir) ->
+clear_sql_tables(sqlite, _BaseDir) ->
ok;
-create_sql_tables(Type, BaseDir) ->
+clear_sql_tables(Type, BaseDir) ->
{VHost, File} = case Type of
mysql ->
Path = case ejabberd_sql:use_new_schema() of
@@ -1012,13 +1012,13 @@ create_sql_tables(Type, BaseDir) ->
end,
SQLFile = filename:join([BaseDir, "sql", File]),
CreationQueries = read_sql_queries(SQLFile),
- DropTableQueries = drop_table_queries(CreationQueries),
+ ClearTableQueries = clear_table_queries(CreationQueries),
case ejabberd_sql:sql_transaction(
- VHost, DropTableQueries ++ CreationQueries) of
+ VHost, ClearTableQueries) of
{atomic, ok} ->
ok;
Err ->
- ct:fail({failed_to_create_sql_tables, Type, Err})
+ ct:fail({failed_to_clear_sql_tables, Type, Err})
end.
read_sql_queries(File) ->
@@ -1029,12 +1029,12 @@ read_sql_queries(File) ->
ct:fail({open_file_failed, File, Err})
end.
-drop_table_queries(Queries) ->
+clear_table_queries(Queries) ->
lists:foldl(
fun(Query, Acc) ->
case split(str:to_lower(Query)) of
[<<"create">>, <<"table">>, Table|_] ->
- [<<"DROP TABLE IF EXISTS ", Table/binary, ";">>|Acc];
+ [<<"DELETE FROM ", Table/binary, ";">>|Acc];
_ ->
Acc
end