summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandru Scvortov <alexandru@rabbitmq.com>2010-08-03 13:47:52 +0100
committerAlexandru Scvortov <alexandru@rabbitmq.com>2010-08-03 13:47:52 +0100
commitcc483697f7cff6c7013ae4a92545496d71f20b4a (patch)
treede91ad22a2b1540d26f25ba0042195db25e26b29
parent1db512b6896c7adfd0a17571d584047af1980f5f (diff)
downloadrabbitmq-server-git-cc483697f7cff6c7013ae4a92545496d71f20b4a.tar.gz
added option parser tests
-rw-r--r--src/rabbit_control.erl6
-rw-r--r--src/rabbit_tests.erl30
2 files changed, 35 insertions, 1 deletions
diff --git a/src/rabbit_control.erl b/src/rabbit_control.erl
index a36dc79ba9..ff15b9137d 100644
--- a/src/rabbit_control.erl
+++ b/src/rabbit_control.erl
@@ -32,7 +32,7 @@
-module(rabbit_control).
-include("rabbit.hrl").
--export([start/0, stop/0, action/5]).
+-export([start/0, stop/0, action/5, get_options/2]).
-define(RPC_TIMEOUT, infinity).
@@ -45,12 +45,16 @@
-ifdef(use_specs).
+-type(optdef() :: {flag, string()} | {option, string(), any()}).
+
-spec(start/0 :: () -> no_return()).
-spec(stop/0 :: () -> 'ok').
-spec(action/5 ::
(atom(), node(), [string()], [{string(), any()}],
fun ((string(), [any()]) -> 'ok'))
-> 'ok').
+-spec(get_options/2 :: ([optdef()], [string()])
+ -> {[string()], [{string(), any()}]}).
-spec(usage/0 :: () -> no_return()).
-endif.
diff --git a/src/rabbit_tests.erl b/src/rabbit_tests.erl
index 195fe39f30..eaf5bc7e52 100644
--- a/src/rabbit_tests.erl
+++ b/src/rabbit_tests.erl
@@ -68,6 +68,7 @@ all_tests() ->
passed = test_app_management(),
passed = test_log_management_during_startup(),
passed = test_memory_pressure(),
+ passed = test_option_parser(),
passed = test_cluster_management(),
passed = test_user_management(),
passed = test_server_status(),
@@ -725,6 +726,30 @@ test_log_management_during_startup() ->
ok = control_action(start_app, []),
passed.
+test_option_parser() ->
+ % command and arguments should just pass through
+ ok = check_get_options({["mock_command", "arg1", "arg2"], []},
+ [], ["mock_command", "arg1", "arg2"]),
+
+ % get flags
+ ok = check_get_options(
+ {["mock_command", "arg1"], [{"-f", true}, {"-f2", false}]},
+ [{flag, "-f"}, {flag, "-f2"}], ["mock_command", "arg1", "-f"]),
+
+ % get options
+ ok = check_get_options(
+ {["mock_command"], [{"-foo", "bar"}, {"-baz", "notbaz"}]},
+ [{option, "-foo", "notfoo"}, {option, "-bax", "notbaz"}],
+ ["mock_command", "-foo", "bar"]),
+
+ % shuffled and interleaved arguments and options
+ ok = check_get_options(
+ {["a1", "a2", "a3"], [{"-o1", "hello"}, {"-o2", "noto2"}, {"-f", true}]},
+ [{option, "-o1", "noto1"}, {flag, "-f"}, {option, "-o2", "noto2"}],
+ ["-f", "a1", "-o1", "hello", "a2", "a3"]),
+
+ passed.
+
test_cluster_management() ->
%% 'cluster' and 'reset' should only work if the app is stopped
@@ -1301,6 +1326,11 @@ expand_options(As, Bs) ->
end
end, Bs, As).
+check_get_options({ExpArgs, ExpOpts}, Defs, Args) ->
+ {ExpArgs, ResOpts} = rabbit_control:get_options(Defs, Args),
+ lists:sort(ExpOpts) == lists:sort(ResOpts), % don't care about the order
+ ok.
+
empty_files(Files) ->
[case file:read_file_info(File) of
{ok, FInfo} -> FInfo#file_info.size == 0;