diff options
author | Evgeny Khramtsov <ekhramtsov@process-one.net> | 2019-10-28 12:09:14 +0300 |
---|---|---|
committer | Evgeny Khramtsov <ekhramtsov@process-one.net> | 2019-10-28 12:09:14 +0300 |
commit | e2b79ea0b64a904dd025e9aab1b6a90778532819 (patch) | |
tree | a78181a7455d247d93f87df9c89ee7309e355f82 /test | |
parent | Merge pull request #3069 from nosnilmot/jwt-custom-jid-field (diff) |
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.
Diffstat (limited to 'test')
-rw-r--r-- | test/README | 2 | ||||
-rw-r--r-- | test/ejabberd_SUITE.erl | 18 |
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 |