diff options
author | Brian Cully <bjc@kublai.com> | 2012-02-09 20:16:55 -0500 |
---|---|---|
committer | Brian Cully <bjc@kublai.com> | 2012-02-09 20:16:55 -0500 |
commit | 9689ca08ba00a8fdc4928438457bb6f56d01f99e (patch) | |
tree | 2bd739771c65987f890cbf36e7525d4d001ad01d /test/mysqlerl_test_lib.erl | |
parent | cda5d31655671546e2c7127f5b9d5da94a75e466 (diff) | |
download | mysqlerl-9689ca08ba00a8fdc4928438457bb6f56d01f99e.tar.gz mysqlerl-9689ca08ba00a8fdc4928438457bb6f56d01f99e.zip |
Move common test functions to their own module.
Diffstat (limited to 'test/mysqlerl_test_lib.erl')
-rw-r--r-- | test/mysqlerl_test_lib.erl | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/test/mysqlerl_test_lib.erl b/test/mysqlerl_test_lib.erl new file mode 100644 index 0000000..a94e8e9 --- /dev/null +++ b/test/mysqlerl_test_lib.erl @@ -0,0 +1,34 @@ +%%% @author Brian Cully <bjc@kublai.com> +%%% @copyright (C) 2012, Brian Cully +%%% @doc +%%% +%%% @end +%%% Created : 9 Feb 2012 by Brian Cully <bjc@kublai.com> + +-module(mysqlerl_test_lib). + +-compile(export_all). + +mysql_cmd(undefined, undefined) -> + "mysql"; +mysql_cmd(User, undefined) -> + io_lib:format("mysql -u'~s'", [User]); +mysql_cmd(undefined, Pass) -> + io_lib:format("mysql -p'~s'", [Pass]); +mysql_cmd(User, Pass) -> + io_lib:format("mysql -u'~s' -p'~s'", [User, Pass]). + +create_db(User, Pass, Name) -> + drop_db(User, Pass, Name), + SQL = io_lib:format("CREATE DATABASE ~s", [Name]), + CMD = mysql_cmd(User, Pass), + os:cmd(io_lib:format("echo '~s' | ~s", [SQL, CMD])). + +drop_db(User, Pass, Name) -> + SQL = io_lib:format("DROP DATABASE IF EXISTS ~s", [Name]), + CMD = mysql_cmd(User, Pass), + os:cmd(io_lib:format("echo '~s' | ~s", [SQL, CMD])). + +create_table(User, Pass, Name, DataDir) -> + CMD = mysql_cmd(User, Pass), + os:cmd(io_lib:format("~s ~s < ~s/table-data.sql", [CMD, Name, DataDir])). |