diff options
author | Jean-Sébastien Pédron <jean-sebastien@rabbitmq.com> | 2016-06-14 11:06:01 +0200 |
---|---|---|
committer | Jean-Sébastien Pédron <jean-sebastien@rabbitmq.com> | 2016-06-14 16:11:58 +0200 |
commit | 555298e7dea8c0c74daf348d481a2f46bb4fd1ec (patch) | |
tree | e58180970d7a1943f86b59a5b0d5aff194bdcd65 /deps/rabbitmq_shovel/test | |
parent | e9ed6bd1d9aba4c76b370fc92ac1d561d588c428 (diff) | |
download | rabbitmq-server-git-555298e7dea8c0c74daf348d481a2f46bb4fd1ec.tar.gz |
Switch testsuite to common_test
[#121411939]
Diffstat (limited to 'deps/rabbitmq_shovel/test')
-rw-r--r-- | deps/rabbitmq_shovel/test/configuration_SUITE.erl (renamed from deps/rabbitmq_shovel/test/src/rabbit_shovel_test.erl) | 208 | ||||
-rw-r--r-- | deps/rabbitmq_shovel/test/dynamic_SUITE.erl (renamed from deps/rabbitmq_shovel/test/src/rabbit_shovel_test_dyn.erl) | 306 | ||||
-rw-r--r-- | deps/rabbitmq_shovel/test/src/rabbit_shovel_test_all.erl | 33 |
3 files changed, 349 insertions, 198 deletions
diff --git a/deps/rabbitmq_shovel/test/src/rabbit_shovel_test.erl b/deps/rabbitmq_shovel/test/configuration_SUITE.erl index 892b80ddea..6a89a8da20 100644 --- a/deps/rabbitmq_shovel/test/src/rabbit_shovel_test.erl +++ b/deps/rabbitmq_shovel/test/configuration_SUITE.erl @@ -1,23 +1,25 @@ -%% The contents of this file are subject to the Mozilla Public License -%% Version 1.1 (the "License"); you may not use this file except in -%% compliance with the License. You may obtain a copy of the License -%% at http://www.mozilla.org/MPL/ +%% The contents of this file are subject to the Mozilla Public License +%% Version 1.1 (the "License"); you may not use this file except in +%% compliance with the License. You may obtain a copy of the License at +%% http://www.mozilla.org/MPL/ %% -%% Software distributed under the License is distributed on an "AS IS" -%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See -%% the License for the specific language governing rights and -%% limitations under the License. +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +%% License for the specific language governing rights and limitations +%% under the License. %% -%% The Original Code is RabbitMQ. +%% The Original Code is RabbitMQ %% -%% The Initial Developer of the Original Code is GoPivotal, Inc. -%% Copyright (c) 2007-2016 Pivotal Software, Inc. All rights reserved. +%% The Initial Developer of the Original Code is GoPivotal, Inc. +%% Copyright (c) 2010-2016 Pivotal Software, Inc. All rights reserved. %% --module(rabbit_shovel_test). --export([test/0]). +-module(configuration_SUITE). + +-include_lib("common_test/include/ct.hrl"). -include_lib("amqp_client/include/amqp_client.hrl"). --include_lib("eunit/include/eunit.hrl"). + +-compile(export_all). -define(EXCHANGE, <<"test_exchange">>). -define(TO_SHOVEL, <<"to_the_shovel">>). @@ -26,14 +28,74 @@ -define(SHOVELLED, <<"shovelled">>). -define(TIMEOUT, 1000). -main_test() -> - %% it may already be running. Stop if possible - application:stop(rabbitmq_shovel), - +all() -> + [ + {group, non_parallel_tests} + ]. + +groups() -> + [ + {non_parallel_tests, [], [ + zero_shovels, + invalid_configuration, + valid_configuration + ]} + ]. + +%% ------------------------------------------------------------------- +%% Testsuite setup/teardown. +%% ------------------------------------------------------------------- + +init_per_suite(Config) -> + rabbit_ct_helpers:log_environment(), + Config1 = rabbit_ct_helpers:set_config(Config, [ + {rmq_nodename_suffix, ?MODULE} + ]), + Config2 = rabbit_ct_helpers:run_setup_steps(Config1, + rabbit_ct_broker_helpers:setup_steps() ++ + rabbit_ct_client_helpers:setup_steps()), + ok = rabbit_ct_broker_helpers:rpc(Config2, 0, + application, stop, [rabbitmq_shovel]), + Config2. + +end_per_suite(Config) -> + ok = rabbit_ct_broker_helpers:rpc(Config, 0, + application, stop, [amqp_client]), + rabbit_ct_helpers:run_teardown_steps(Config, + rabbit_ct_client_helpers:teardown_steps() ++ + rabbit_ct_broker_helpers:teardown_steps()). + +init_per_group(_, Config) -> + Config. + +end_per_group(_, Config) -> + Config. + +init_per_testcase(Testcase, Config) -> + rabbit_ct_helpers:testcase_started(Config, Testcase). + +end_per_testcase(Testcase, Config) -> + rabbit_ct_helpers:testcase_finished(Config, Testcase). + +%% ------------------------------------------------------------------- +%% Testcases. +%% ------------------------------------------------------------------- + +zero_shovels(Config) -> + passed = rabbit_ct_broker_helpers:rpc(Config, 0, + ?MODULE, zero_shovels1, [Config]). + +zero_shovels1(_Config) -> %% shovel can be started with zero shovels configured ok = application:start(rabbitmq_shovel), ok = application:stop(rabbitmq_shovel), + passed. +invalid_configuration(Config) -> + passed = rabbit_ct_broker_helpers:rpc(Config, 0, + ?MODULE, invalid_configuration1, [Config]). + +invalid_configuration1(_Config) -> %% various ways of breaking the config require_list_of_shovel_configurations = test_broken_shovel_configs(invalid_config), @@ -133,37 +195,29 @@ main_test() -> {require_boolean, '42'}}, _} = test_broken_shovel_sources([{broker, "amqps://username:password@host:5673/vhost?cacertfile=/path/to/cacert.pem&certfile=/path/to/certfile.pem&keyfile=/path/to/keyfile.pem&verify=verify_peer&fail_if_no_peer_cert=42"}]), - %% a working config - application:set_env( - rabbitmq_shovel, - shovels, - [{test_shovel, - [{sources, - [{broker, "amqp:///%2f?heartbeat=5"}, - {declarations, - [{'queue.declare', [exclusive, auto_delete]}, - {'exchange.declare', [{exchange, ?EXCHANGE}, auto_delete]}, - {'queue.bind', [{queue, <<>>}, {exchange, ?EXCHANGE}, - {routing_key, ?TO_SHOVEL}]} - ]}]}, - {destinations, - [{broker, "amqp:///%2f"}]}, - {queue, <<>>}, - {ack_mode, on_confirm}, - {publish_fields, [{exchange, ?EXCHANGE}, {routing_key, ?FROM_SHOVEL}]}, - {publish_properties, [{delivery_mode, 2}, - {cluster_id, <<"my-cluster">>}, - {content_type, ?SHOVELLED}]}, - {add_forward_headers, true} - ]}], - infinity), + passed. - ok = application:start(rabbitmq_shovel), +test_broken_shovel_configs(Configs) -> + application:set_env(rabbitmq_shovel, shovels, Configs), + {error, {Error, _}} = application:start(rabbitmq_shovel), + Error. - await_running_shovel(test_shovel), +test_broken_shovel_config(Config) -> + {invalid_shovel_configuration, test_shovel, Error} = + test_broken_shovel_configs([{test_shovel, Config}]), + Error. - {ok, Conn} = amqp_connection:start(#amqp_params_network{}), - {ok, Chan} = amqp_connection:open_channel(Conn), +test_broken_shovel_sources(Sources) -> + {invalid_parameter_value, sources, Error} = + test_broken_shovel_config([{sources, Sources}, + {destinations, [{broker, "amqp://"}]}, + {queue, <<"">>}]), + Error. + +valid_configuration(Config) -> + ok = setup_shovels(Config), + + Chan = rabbit_ct_client_helpers:open_channel(Config, 0), #'queue.declare_ok'{ queue = Q } = amqp_channel:call(Chan, #'queue.declare' { exclusive = true }), @@ -206,7 +260,8 @@ main_test() -> end, [{test_shovel, static, {running, _Info}, _Time}] = - rabbit_shovel_status:status(), + rabbit_ct_broker_helpers:rpc(Config, 0, + rabbit_shovel_status, status, []), receive {#'basic.deliver' { consumer_tag = CTag, delivery_tag = AckTag1, @@ -219,31 +274,50 @@ main_test() -> after ?TIMEOUT -> throw(timeout_waiting_for_deliver2) end, - amqp_channel:close(Chan), - amqp_connection:close(Conn), - - ok. + rabbit_ct_client_helpers:close_channel(Chan). -test_broken_shovel_configs(Configs) -> - application:set_env(rabbitmq_shovel, shovels, Configs), - {error, {Error, _}} = application:start(rabbitmq_shovel), - Error. +setup_shovels(Config) -> + ok = rabbit_ct_broker_helpers:rpc(Config, 0, + ?MODULE, setup_shovels1, [Config]). -test_broken_shovel_config(Config) -> - {invalid_shovel_configuration, test_shovel, Error} = - test_broken_shovel_configs([{test_shovel, Config}]), - Error. +setup_shovels1(Config) -> + Hostname = ?config(rmq_hostname, Config), + TcpPort = rabbit_ct_broker_helpers:get_node_config(Config, 0, + tcp_port_amqp), + %% a working config + application:set_env( + rabbitmq_shovel, + shovels, + [{test_shovel, + [{sources, + [{broker, rabbit_misc:format("amqp://~s:~b/%2f?heartbeat=5", + [Hostname, TcpPort])}, + {declarations, + [{'queue.declare', [exclusive, auto_delete]}, + {'exchange.declare', [{exchange, ?EXCHANGE}, auto_delete]}, + {'queue.bind', [{queue, <<>>}, {exchange, ?EXCHANGE}, + {routing_key, ?TO_SHOVEL}]} + ]}]}, + {destinations, + [{broker, rabbit_misc:format("amqp://~s:~b/%2f", + [Hostname, TcpPort])}]}, + {queue, <<>>}, + {ack_mode, on_confirm}, + {publish_fields, [{exchange, ?EXCHANGE}, {routing_key, ?FROM_SHOVEL}]}, + {publish_properties, [{delivery_mode, 2}, + {cluster_id, <<"my-cluster">>}, + {content_type, ?SHOVELLED}]}, + {add_forward_headers, true} + ]}], + infinity), -test_broken_shovel_sources(Sources) -> - {invalid_parameter_value, sources, Error} = - test_broken_shovel_config([{sources, Sources}, - {destinations, [{broker, "amqp://"}]}, - {queue, <<"">>}]), - Error. + ok = application:start(rabbitmq_shovel), + await_running_shovel(test_shovel). await_running_shovel(Name) -> - case [Name || {Name, _, {running, _}, _} - <- rabbit_shovel_status:status()] of + case [N || {N, _, {running, _}, _} + <- rabbit_shovel_status:status(), + N =:= Name] of [_] -> ok; _ -> timer:sleep(100), await_running_shovel(Name) diff --git a/deps/rabbitmq_shovel/test/src/rabbit_shovel_test_dyn.erl b/deps/rabbitmq_shovel/test/dynamic_SUITE.erl index b6571e7078..8f39f61944 100644 --- a/deps/rabbitmq_shovel/test/src/rabbit_shovel_test_dyn.erl +++ b/deps/rabbitmq_shovel/test/dynamic_SUITE.erl @@ -14,35 +14,92 @@ %% Copyright (c) 2007-2016 Pivotal Software, Inc. All rights reserved. %% --module(rabbit_shovel_test_dyn). +-module(dynamic_SUITE). --include_lib("eunit/include/eunit.hrl"). +-include_lib("common_test/include/ct.hrl"). -include_lib("amqp_client/include/amqp_client.hrl"). --import(rabbit_misc, [pget/2]). - -simple_test() -> - with_ch( +-compile(export_all). + +all() -> + [ + {group, non_parallel_tests} + ]. + +groups() -> + [ + {non_parallel_tests, [], [ + simple, + set_properties, + exchange, + restart, + change_definition, + autodelete, + validation, + security_validation + ]} + ]. + +%% ------------------------------------------------------------------- +%% Testsuite setup/teardown. +%% ------------------------------------------------------------------- + +init_per_suite(Config) -> + rabbit_ct_helpers:log_environment(), + Config1 = rabbit_ct_helpers:set_config(Config, [ + {rmq_nodename_suffix, ?MODULE} + ]), + Config2 = rabbit_ct_helpers:run_setup_steps(Config1, + rabbit_ct_broker_helpers:setup_steps() ++ + rabbit_ct_client_helpers:setup_steps()), + Config2. + +end_per_suite(Config) -> + ok = rabbit_ct_broker_helpers:rpc(Config, 0, + application, stop, [amqp_client]), + rabbit_ct_helpers:run_teardown_steps(Config, + rabbit_ct_client_helpers:teardown_steps() ++ + rabbit_ct_broker_helpers:teardown_steps()). + +init_per_group(_, Config) -> + Config. + +end_per_group(_, Config) -> + Config. + +init_per_testcase(Testcase, Config) -> + rabbit_ct_helpers:testcase_started(Config, Testcase). + +end_per_testcase(Testcase, Config) -> + rabbit_ct_helpers:testcase_finished(Config, Testcase). + +%% ------------------------------------------------------------------- +%% Testcases. +%% ------------------------------------------------------------------- + +simple(Config) -> + with_ch(Config, fun (Ch) -> - set_param(<<"test">>, [{<<"src-queue">>, <<"src">>}, + set_param(Config, + <<"test">>, [{<<"src-queue">>, <<"src">>}, {<<"dest-queue">>, <<"dest">>}]), publish_expect(Ch, <<>>, <<"src">>, <<"dest">>, <<"hello">>) end). -set_properties_test() -> - with_ch( +set_properties(Config) -> + with_ch(Config, fun (Ch) -> Ps = [{<<"src-queue">>, <<"src">>}, {<<"dest-queue">>, <<"dest">>}, {<<"publish-properties">>, [{<<"cluster_id">>, <<"x">>}]}], - set_param(<<"test">>, Ps), + set_param(Config, <<"test">>, Ps), #amqp_msg{props = #'P_basic'{cluster_id = Cluster}} = publish_expect(Ch, <<>>, <<"src">>, <<"dest">>, <<"hi">>), - ?assertEqual(<<"x">>, Cluster) + <<"x">> = Cluster end). -exchange_test() -> - with_ch( +exchange(Config) -> + with_ch(Config, fun (Ch) -> amqp_channel:call(Ch, #'queue.declare'{queue = <<"queue">>, durable = true}), @@ -50,12 +107,14 @@ exchange_test() -> Ch, #'queue.bind'{queue = <<"queue">>, exchange = <<"amq.topic">>, routing_key = <<"test-key">>}), - set_param(<<"test">>, [{<<"src-exchange">>, <<"amq.direct">>}, + set_param(Config, + <<"test">>, [{<<"src-exchange">>, <<"amq.direct">>}, {<<"src-exchange-key">>,<<"test-key">>}, {<<"dest-exchange">>, <<"amq.topic">>}]), publish_expect(Ch, <<"amq.direct">>, <<"test-key">>, <<"queue">>, <<"hello">>), - set_param(<<"test">>, [{<<"src-exchange">>, <<"amq.direct">>}, + set_param(Config, + <<"test">>, [{<<"src-exchange">>, <<"amq.direct">>}, {<<"src-exchange-key">>, <<"test-key">>}, {<<"dest-exchange">>, <<"amq.topic">>}, {<<"dest-exchange-key">>,<<"new-key">>}]), @@ -69,118 +128,151 @@ exchange_test() -> <<"queue">>, <<"hello">>) end). -restart_test() -> - with_ch( +restart(Config) -> + with_ch(Config, fun (Ch) -> - set_param(<<"test">>, [{<<"src-queue">>, <<"src">>}, + set_param(Config, + <<"test">>, [{<<"src-queue">>, <<"src">>}, {<<"dest-queue">>, <<"dest">>}]), %% The catch is because connections link to the shovel, %% so one connection will die, kill the shovel, kill %% the other connection, then we can't close it - [catch amqp_connection:close(C) || C <- rabbit_direct:list()], + Conns = rabbit_ct_broker_helpers:rpc(Config, 0, + rabbit_direct, list, []), + [catch amqp_connection:close(C) || C <- Conns], publish_expect(Ch, <<>>, <<"src">>, <<"dest">>, <<"hello">>) end). -change_definition_test() -> - with_ch( +change_definition(Config) -> + with_ch(Config, fun (Ch) -> - set_param(<<"test">>, [{<<"src-queue">>, <<"src">>}, + set_param(Config, + <<"test">>, [{<<"src-queue">>, <<"src">>}, {<<"dest-queue">>, <<"dest">>}]), publish_expect(Ch, <<>>, <<"src">>, <<"dest">>, <<"hello">>), - set_param(<<"test">>, [{<<"src-queue">>, <<"src">>}, + set_param(Config, + <<"test">>, [{<<"src-queue">>, <<"src">>}, {<<"dest-queue">>, <<"dest2">>}]), publish_expect(Ch, <<>>, <<"src">>, <<"dest2">>, <<"hello">>), expect_empty(Ch, <<"dest">>), - clear_param(<<"test">>), + clear_param(Config, <<"test">>), publish_expect(Ch, <<>>, <<"src">>, <<"src">>, <<"hello">>), expect_empty(Ch, <<"dest">>), expect_empty(Ch, <<"dest2">>) end). -autodelete_test_() -> - [autodelete_case({<<"on-confirm">>, <<"queue-length">>, 0, 100}), - autodelete_case({<<"on-confirm">>, 50, 50, 50}), - autodelete_case({<<"on-publish">>, <<"queue-length">>, 0, 100}), - autodelete_case({<<"on-publish">>, 50, 50, 50}), - %% no-ack is not compatible with explicit count - autodelete_case({<<"no-ack">>, <<"queue-length">>, 0, 100})]. +autodelete(Config) -> + autodelete_case(Config, {<<"on-confirm">>, <<"queue-length">>, 0, 100}), + autodelete_case(Config, {<<"on-confirm">>, 50, 50, 50}), + autodelete_case(Config, {<<"on-publish">>, <<"queue-length">>, 0, 100}), + autodelete_case(Config, {<<"on-publish">>, 50, 50, 50}), + %% no-ack is not compatible with explicit count + autodelete_case(Config, {<<"no-ack">>, <<"queue-length">>, 0, 100}). -autodelete_case(Args) -> - fun () -> with_ch(autodelete_do(Args)) end. +autodelete_case(Config, Args) -> + with_ch(Config, autodelete_do(Config, Args)). -autodelete_do({AckMode, After, ExpSrc, ExpDest}) -> +autodelete_do(Config, {AckMode, After, ExpSrc, ExpDest}) -> fun (Ch) -> amqp_channel:call(Ch, #'confirm.select'{}), amqp_channel:call(Ch, #'queue.declare'{queue = <<"src">>}), publish_count(Ch, <<>>, <<"src">>, <<"hello">>, 100), amqp_channel:wait_for_confirms(Ch), - set_param_nowait(<<"test">>, [{<<"src-queue">>, <<"src">>}, + set_param_nowait(Config, + <<"test">>, [{<<"src-queue">>, <<"src">>}, {<<"dest-queue">>, <<"dest">>}, {<<"ack-mode">>, AckMode}, {<<"delete-after">>, After}]), - await_autodelete(<<"test">>), + await_autodelete(Config, <<"test">>), expect_count(Ch, <<"src">>, <<"hello">>, ExpSrc), expect_count(Ch, <<"dest">>, <<"hello">>, ExpDest) end. -validation_test() -> +validation(Config) -> URIs = [{<<"src-uri">>, <<"amqp://">>}, {<<"dest-uri">>, <<"amqp://">>}], %% Need valid src and dest URIs - invalid_param([]), - invalid_param([{<<"src-queue">>, <<"test">>}, + invalid_param(Config, []), + invalid_param(Config, + [{<<"src-queue">>, <<"test">>}, {<<"src-uri">>, <<"derp">>}, {<<"dest-uri">>, <<"amqp://">>}]), - invalid_param([{<<"src-queue">>, <<"test">>}, + invalid_param(Config, + [{<<"src-queue">>, <<"test">>}, {<<"src-uri">>, [<<"derp">>]}, {<<"dest-uri">>, <<"amqp://">>}]), - invalid_param([{<<"src-queue">>, <<"test">>}, + invalid_param(Config, + [{<<"src-queue">>, <<"test">>}, {<<"dest-uri">>, <<"amqp://">>}]), %% Also need src exchange or queue - invalid_param(URIs), - valid_param([{<<"src-exchange">>, <<"test">>} | URIs]), + invalid_param(Config, + URIs), + valid_param(Config, + [{<<"src-exchange">>, <<"test">>} | URIs]), QURIs = [{<<"src-queue">>, <<"test">>} | URIs], - valid_param(QURIs), + valid_param(Config, QURIs), %% But not both - invalid_param([{<<"src-exchange">>, <<"test">>} | QURIs]), + invalid_param(Config, + [{<<"src-exchange">>, <<"test">>} | QURIs]), %% Check these are of right type - invalid_param([{<<"prefetch-count">>, <<"three">>} | QURIs]), - invalid_param([{<<"reconnect-delay">>, <<"three">>} | QURIs]), - invalid_param([{<<"ack-mode">>, <<"whenever">>} | QURIs]), - invalid_param([{<<"delete-after">>, <<"whenever">>} | QURIs]), + invalid_param(Config, + [{<<"prefetch-count">>, <<"three">>} | QURIs]), + invalid_param(Config, + [{<<"reconnect-delay">>, <<"three">>} | QURIs]), + invalid_param(Config, + [{<<"ack-mode">>, <<"whenever">>} | QURIs]), + invalid_param(Config, + [{<<"delete-after">>, <<"whenever">>} | QURIs]), %% Check properties have to look property-ish - invalid_param([{<<"publish-properties">>, [{<<"nonexistent">>, <<>>}]}]), - invalid_param([{<<"publish-properties">>, [{<<"cluster_id">>, 2}]}]), - invalid_param([{<<"publish-properties">>, <<"something">>}]), + invalid_param(Config, + [{<<"publish-properties">>, [{<<"nonexistent">>, <<>>}]}]), + invalid_param(Config, + [{<<"publish-properties">>, [{<<"cluster_id">>, 2}]}]), + invalid_param(Config, + [{<<"publish-properties">>, <<"something">>}]), %% Can't use explicit message count and no-ack together - invalid_param([{<<"delete-after">>, 1}, + invalid_param(Config, + [{<<"delete-after">>, 1}, {<<"ack-mode">>, <<"no-ack">>} | QURIs]), ok. -security_validation_test() -> - [begin - rabbit_vhost:add(U), - rabbit_auth_backend_internal:add_user(U, <<>>), - rabbit_auth_backend_internal:set_permissions( - U, U, <<".*">>, <<".*">>, <<".*">>) - end || U <- [<<"a">>, <<"b">>]], +security_validation(Config) -> + ok = rabbit_ct_broker_helpers:rpc(Config, 0, + ?MODULE, security_validation_add_user, []), Qs = [{<<"src-queue">>, <<"test">>}, {<<"dest-queue">>, <<"test2">>}], - A = lookup_user(<<"a">>), - valid_param([{<<"src-uri">>, <<"amqp:///a">>}, + A = lookup_user(Config, <<"a">>), + valid_param(Config, [{<<"src-uri">>, <<"amqp:///a">>}, {<<"dest-uri">>, <<"amqp:///a">>} | Qs], A), - invalid_param([{<<"src-uri">>, <<"amqp:///a">>}, + invalid_param(Config, + [{<<"src-uri">>, <<"amqp:///a">>}, {<<"dest-uri">>, <<"amqp:///b">>} | Qs], A), - invalid_param([{<<"src-uri">>, <<"amqp:///b">>}, + invalid_param(Config, + [{<<"src-uri">>, <<"amqp:///b">>}, {<<"dest-uri">>, <<"amqp:///a">>} | Qs], A), + + ok = rabbit_ct_broker_helpers:rpc(Config, 0, + ?MODULE, security_validation_remove_user, []), + ok. + +security_validation_add_user() -> + [begin + rabbit_vhost:add(U), + rabbit_auth_backend_internal:add_user(U, <<>>), + rabbit_auth_backend_internal:set_permissions( + U, U, <<".*">>, <<".*">>, <<".*">>) + end || U <- [<<"a">>, <<"b">>]], + ok. + +security_validation_remove_user() -> [begin rabbit_vhost:delete(U), rabbit_auth_backend_internal:delete_user(U) @@ -189,12 +281,11 @@ security_validation_test() -> %%---------------------------------------------------------------------------- -with_ch(Fun) -> - {ok, Conn} = amqp_connection:start(#amqp_params_network{}), - {ok, Ch} = amqp_connection:open_channel(Conn), +with_ch(Config, Fun) -> + Ch = rabbit_ct_client_helpers:open_channel(Config, 0), Fun(Ch), - amqp_connection:close(Conn), - cleanup(), + rabbit_ct_client_helpers:close_channel(Ch), + cleanup(Config), ok. publish(Ch, X, Key, Payload) when is_binary(Payload) -> @@ -211,8 +302,8 @@ publish_expect(Ch, X, Key, Q, Payload) -> expect(Ch, Q, Payload) -> amqp_channel:subscribe(Ch, #'basic.consume'{queue = Q, no_ack = true}, self()), - receive - #'basic.consume_ok'{consumer_tag = CTag} -> ok + CTag = receive + #'basic.consume_ok'{consumer_tag = CT} -> CT end, Msg = receive {#'basic.deliver'{}, #amqp_msg{payload = Payload} = M} -> @@ -224,8 +315,7 @@ expect(Ch, Q, Payload) -> Msg. expect_empty(Ch, Q) -> - ?assertMatch(#'basic.get_empty'{}, - amqp_channel:call(Ch, #'basic.get'{ queue = Q })). + #'basic.get_empty'{} = amqp_channel:call(Ch, #'basic.get'{ queue = Q }). publish_count(Ch, X, Key, M, Count) -> [publish(Ch, X, Key, M) || _ <- lists:seq(1, Count)]. @@ -234,46 +324,66 @@ expect_count(Ch, Q, M, Count) -> [expect(Ch, Q, M) || _ <- lists:seq(1, Count)], expect_empty(Ch, Q). -set_param(Name, Value) -> - set_param_nowait(Name, Value), - await_shovel(Name). +set_param(Config, Name, Value) -> + set_param_nowait(Config, Name, Value), + await_shovel(Config, Name). -set_param_nowait(Name, Value) -> - ok = rabbit_runtime_parameters:set( - <<"/">>, <<"shovel">>, Name, [{<<"src-uri">>, <<"amqp://">>}, - {<<"dest-uri">>, [<<"amqp://">>]} | - Value], none). +set_param_nowait(Config, Name, Value) -> + ok = rabbit_ct_broker_helpers:rpc(Config, 0, + rabbit_runtime_parameters, set, [ + <<"/">>, <<"shovel">>, Name, [{<<"src-uri">>, <<"amqp://">>}, + {<<"dest-uri">>, [<<"amqp://">>]} | + Value], none]). + +invalid_param(Config, Value, User) -> + {error_string, _} = rabbit_ct_broker_helpers:rpc(Config, 0, + rabbit_runtime_parameters, set, + [<<"/">>, <<"shovel">>, <<"invalid">>, Value, User]). -invalid_param(Value, User) -> - {error_string, _} = rabbit_runtime_parameters:set( - <<"/">>, <<"shovel">>, <<"invalid">>, Value, User). +valid_param(Config, Value, User) -> + rabbit_ct_broker_helpers:rpc(Config, 0, + ?MODULE, valid_param1, [Config, Value, User]). -valid_param(Value, User) -> +valid_param1(_Config, Value, User) -> ok = rabbit_runtime_parameters:set( <<"/">>, <<"shovel">>, <<"a">>, Value, User), ok = rabbit_runtime_parameters:clear(<<"/">>, <<"shovel">>, <<"a">>). -invalid_param(Value) -> invalid_param(Value, none). -valid_param(Value) -> valid_param(Value, none). +invalid_param(Config, Value) -> invalid_param(Config, Value, none). +valid_param(Config, Value) -> valid_param(Config, Value, none). -lookup_user(Name) -> - {ok, User} = rabbit_access_control:check_user_login(Name, []), +lookup_user(Config, Name) -> + {ok, User} = rabbit_ct_broker_helpers:rpc(Config, 0, + rabbit_access_control, check_user_login, [Name, []]), User. -clear_param(Name) -> - rabbit_runtime_parameters:clear(<<"/">>, <<"shovel">>, Name). +clear_param(Config, Name) -> + rabbit_ct_broker_helpers:rpc(Config, 0, + rabbit_runtime_parameters, clear, [<<"/">>, <<"shovel">>, Name]). + +cleanup(Config) -> + rabbit_ct_broker_helpers:rpc(Config, 0, + ?MODULE, cleanup1, [Config]). -cleanup() -> - [rabbit_runtime_parameters:clear(pget(vhost, P), - pget(component, P), - pget(name, P)) || +cleanup1(_Config) -> + [rabbit_runtime_parameters:clear(rabbit_misc:pget(vhost, P), + rabbit_misc:pget(component, P), + rabbit_misc:pget(name, P)) || P <- rabbit_runtime_parameters:list()], [rabbit_amqqueue:delete(Q, false, false) || Q <- rabbit_amqqueue:list()]. -await_shovel(Name) -> +await_shovel(Config, Name) -> + rabbit_ct_broker_helpers:rpc(Config, 0, + ?MODULE, await_shovel1, [Config, Name]). + +await_shovel1(_Config, Name) -> await(fun () -> lists:member(Name, shovels_from_status()) end). -await_autodelete(Name) -> +await_autodelete(Config, Name) -> + rabbit_ct_broker_helpers:rpc(Config, 0, + ?MODULE, await_autodelete1, [Config, Name]). + +await_autodelete1(_Config, Name) -> await(fun () -> not lists:member(Name, shovels_from_parameters()) end), await(fun () -> not lists:member(Name, shovels_from_status()) end). @@ -290,4 +400,4 @@ shovels_from_status() -> shovels_from_parameters() -> L = rabbit_runtime_parameters:list(<<"/">>, <<"shovel">>), - [pget(name, Shovel) || Shovel <- L]. + [rabbit_misc:pget(name, Shovel) || Shovel <- L]. diff --git a/deps/rabbitmq_shovel/test/src/rabbit_shovel_test_all.erl b/deps/rabbitmq_shovel/test/src/rabbit_shovel_test_all.erl deleted file mode 100644 index 2269ea8562..0000000000 --- a/deps/rabbitmq_shovel/test/src/rabbit_shovel_test_all.erl +++ /dev/null @@ -1,33 +0,0 @@ -%% The contents of this file are subject to the Mozilla Public License -%% Version 1.1 (the "License"); you may not use this file except in -%% compliance with the License. You may obtain a copy of the License at -%% http://www.mozilla.org/MPL/ -%% -%% Software distributed under the License is distributed on an "AS IS" -%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the -%% License for the specific language governing rights and limitations -%% under the License. -%% -%% The Original Code is RabbitMQ -%% -%% The Initial Developer of the Original Code is GoPivotal, Inc. -%% Copyright (c) 2010-2015 Pivotal Software, Inc. All rights reserved. -%% - --module(rabbit_shovel_test_all). - --export([all_tests/0]). - -all_tests() -> - ok = eunit:test(tests(rabbit_shovel_test, 60), [verbose]), - ok = eunit:test(tests(rabbit_shovel_test_dyn, 60), [verbose]). - -tests(Module, Timeout) -> - {foreach, fun() -> ok end, - [{timeout, Timeout, fun () -> Module:F() end} || F <- funs(Module, "_test")] ++ - [{timeout, Timeout, Fun} || Gen <- funs(Module, "_test_"), - Fun <- Module:Gen()]}. - -funs(Module, Suffix) -> - [F || {F, _Arity} <- proplists:get_value(exports, Module:module_info()), - string:right(atom_to_list(F), length(Suffix)) =:= Suffix]. |