diff options
author | Emile Joubert <emile@rabbitmq.com> | 2012-10-12 17:09:50 +0100 |
---|---|---|
committer | Emile Joubert <emile@rabbitmq.com> | 2012-10-12 17:09:50 +0100 |
commit | 5c9503287fa53f03e81e187dcfb01dc98a83dd99 (patch) | |
tree | dcc45e21fb8394fb7d9297582e7c0fb248e516c2 /src | |
parent | c1446f87de4add3541738b342b25dd4f427aa288 (diff) | |
download | rabbitmq-server-5c9503287fa53f03e81e187dcfb01dc98a83dd99.tar.gz |
Simplify policy validation tests
Diffstat (limited to 'src')
-rw-r--r-- | src/rabbit_runtime_parameters_test.erl | 19 | ||||
-rw-r--r-- | src/rabbit_tests.erl | 25 |
2 files changed, 10 insertions, 34 deletions
diff --git a/src/rabbit_runtime_parameters_test.erl b/src/rabbit_runtime_parameters_test.erl index 63e60490..d4d7271e 100644 --- a/src/rabbit_runtime_parameters_test.erl +++ b/src/rabbit_runtime_parameters_test.erl @@ -53,31 +53,16 @@ unregister_policy_validator() -> rabbit_registry:unregister(policy_validator, <<"testpos">>). validate_policy([{<<"testeven">>, Terms}]) when is_list(Terms) -> - case check_even(Terms) of + case length(Terms) rem 2 =:= 0 of true -> ok; false -> {error, "meh", []} end; validate_policy([{<<"testpos">>, Terms}]) when is_list(Terms) -> - case check_pos(Terms) of + case lists:all(fun (N) -> is_integer(N) andalso N > 0 end, Terms) of true -> ok; false -> {error, "meh", []} end; -validate_policy([{Tag1, Arg1}, {Tag2, Arg2}]) - when is_list(Arg1), is_list(Arg2) -> - case [Tag1, Tag2] -- [<<"testpos">>, <<"testeven">>] of - [] -> case check_pos (Arg1) andalso check_pos (Arg2) andalso - check_even(Arg1) andalso check_even(Arg2) of - true -> ok; - _ -> {error, "meh", []} - end; - _ -> {error, "meh", []} - end; - validate_policy(_) -> {error, "meh", []}. - -check_even(Terms) -> length(Terms) rem 2 =:= 0. -check_pos(Terms) -> lists:all(fun (N) -> is_integer(N) andalso - N > 0 end, Terms). diff --git a/src/rabbit_tests.erl b/src/rabbit_tests.erl index a4cc89a0..2c416c76 100644 --- a/src/rabbit_tests.erl +++ b/src/rabbit_tests.erl @@ -1032,29 +1032,20 @@ test_runtime_parameters() -> test_policy_validation() -> rabbit_runtime_parameters_test:register_policy_validator(), SetPol = - fun (TagValList) -> - Frag = lists:foldl( - fun ({Pol, Val}, Acc) -> - [rabbit_misc:format("\"~s\":~p", [Pol, Val]) | - Acc] - end, "", TagValList), + fun (Tag, Val) -> control_action( set_policy, - ["name", ".*", "{" ++ string:join(Frag, ",") ++ "}"]) + ["name", ".*", rabbit_misc:format("{\"~s\":~p}", [Tag, Val])]) end, - ok = SetPol([{"testeven", []}]), - ok = SetPol([{"testeven", [1, 2]}]), - ok = SetPol([{"testeven", [1, 2, 3, 4]}]), - ok = SetPol([{"testpos", [2, 3, 5, 562]}]), + ok = SetPol("testeven", []), + ok = SetPol("testeven", [1, 2]), + ok = SetPol("testeven", [1, 2, 3, 4]), + ok = SetPol("testpos", [2, 5, 5678]), - {error_string, _} = SetPol([{"testpos", [-1, 0, 1]}]), - {error_string, _} = SetPol([{"testeven", [ 1, 2, 3]}]), + {error_string, _} = SetPol("testpos", [-1, 0, 1]), + {error_string, _} = SetPol("testeven", [ 1, 2, 3]), - ok = SetPol([{"testpos", [2, 16]}, {"testeven", [12, 24]}]), - {error_string, _} = SetPol([{"testpos", [2, 16, 32]}, {"testeven", [12, 24]}]), - {error_string, _} = SetPol([{"testpos", [2, 16]}, {"testeven", [12, -2]}]), - {error_string, _} = SetPol([{"not_registered", []}]), rabbit_runtime_parameters_test:unregister_policy_validator(), passed. |