|
| 1 | +-module(rabbit_amqqueue_SUITE). |
| 2 | + |
| 3 | +-compile([export_all, nowarn_export_all]). |
| 4 | + |
| 5 | +-include_lib("common_test/include/ct.hrl"). |
| 6 | +-include_lib("eunit/include/eunit.hrl"). |
| 7 | +-include_lib("amqp_client/include/amqp_client.hrl"). |
| 8 | + |
| 9 | +%%%=================================================================== |
| 10 | +%%% Common Test callbacks |
| 11 | +%%%=================================================================== |
| 12 | + |
| 13 | +all() -> |
| 14 | + [ |
| 15 | + {group, rabbit_amqqueue_tests} |
| 16 | + ]. |
| 17 | + |
| 18 | + |
| 19 | +all_tests() -> |
| 20 | + [ |
| 21 | + normal_queue_delete_with, |
| 22 | + internal_queue_delete_with |
| 23 | + ]. |
| 24 | + |
| 25 | +groups() -> |
| 26 | + [ |
| 27 | + {rabbit_amqqueue_tests, [], all_tests()} |
| 28 | + ]. |
| 29 | + |
| 30 | +init_per_suite(Config) -> |
| 31 | + rabbit_ct_helpers:log_environment(), |
| 32 | + rabbit_ct_helpers:run_setup_steps(Config). |
| 33 | + |
| 34 | +end_per_suite(Config) -> |
| 35 | + rabbit_ct_helpers:run_teardown_steps(Config). |
| 36 | + |
| 37 | +init_per_group(_Group, Config) -> |
| 38 | + rabbit_ct_helpers:run_steps(Config, |
| 39 | + rabbit_ct_broker_helpers:setup_steps()). |
| 40 | + |
| 41 | +end_per_group(_Group, Config) -> |
| 42 | + rabbit_ct_helpers:run_steps(Config, |
| 43 | + rabbit_ct_broker_helpers:teardown_steps()). |
| 44 | + |
| 45 | +init_per_testcase(Testcase, Config) -> |
| 46 | + Config1 = rabbit_ct_helpers:testcase_started(Config, Testcase), |
| 47 | + rabbit_ct_helpers:run_steps(Config1, |
| 48 | + rabbit_ct_client_helpers:setup_steps()). |
| 49 | + |
| 50 | +end_per_testcase(Testcase, Config) -> |
| 51 | + Config1 = rabbit_ct_helpers:run_steps( |
| 52 | + Config, |
| 53 | + rabbit_ct_client_helpers:teardown_steps()), |
| 54 | + rabbit_ct_helpers:testcase_finished(Config1, Testcase). |
| 55 | + |
| 56 | +%%%=================================================================== |
| 57 | +%%% Test cases |
| 58 | +%%%=================================================================== |
| 59 | + |
| 60 | +normal_queue_delete_with(Config) -> |
| 61 | + QName = queue_name(Config, <<"normal">>), |
| 62 | + Node = rabbit_ct_broker_helpers:get_node_config(Config, 0, nodename), |
| 63 | + Queue = amqqueue:new(QName, |
| 64 | + none, %% pid |
| 65 | + true, %% durable |
| 66 | + false, %% auto delete |
| 67 | + none, %% owner, |
| 68 | + [], |
| 69 | + <<"/">>, |
| 70 | + #{}, |
| 71 | + rabbit_classic_queue), |
| 72 | + |
| 73 | + ?assertMatch({new, _Q}, rabbit_ct_broker_helpers:rpc(Config, 0, rabbit_queue_type, declare, [Queue, Node])), |
| 74 | + |
| 75 | + ?assertMatch({ok, _}, rabbit_ct_broker_helpers:rpc(Config, 0, rabbit_amqqueue, delete_with, [QName, false, false, <<"dummy">>])), |
| 76 | + |
| 77 | + ?assertMatch({error, not_found}, rabbit_ct_broker_helpers:rpc(Config, 0, rabbit_amqqueue, lookup, [QName])), |
| 78 | + |
| 79 | + ok. |
| 80 | + |
| 81 | +internal_queue_delete_with(Config) -> |
| 82 | + QName = queue_name(Config, <<"internal_protected">>), |
| 83 | + Node = rabbit_ct_broker_helpers:get_node_config(Config, 0, nodename), |
| 84 | + Queue = amqqueue:new(QName, |
| 85 | + none, %% pid |
| 86 | + true, %% durable |
| 87 | + false, %% auto delete |
| 88 | + none, %% owner, |
| 89 | + [], |
| 90 | + <<"/">>, |
| 91 | + #{}, |
| 92 | + rabbit_classic_queue), |
| 93 | + IQueue = amqqueue:make_internal(Queue, rabbit_misc:r(<<"/">>, exchange, <<"amq.default">>)), |
| 94 | + |
| 95 | + ?assertMatch({new, _Q}, rabbit_ct_broker_helpers:rpc(Config, 0, rabbit_queue_type, declare, [IQueue, Node])), |
| 96 | + |
| 97 | + ?assertException(exit, {exception, |
| 98 | + {amqp_error, resource_locked, |
| 99 | + "Cannot delete protected queue 'rabbit_amqqueue_tests/internal_protected' in vhost '/'.", |
| 100 | + none}}, rabbit_ct_broker_helpers:rpc(Config, 0, rabbit_amqqueue, delete_with, [QName, false, false, <<"dummy">>])), |
| 101 | + |
| 102 | + ?assertMatch({ok, _}, rabbit_ct_broker_helpers:rpc(Config, 0, rabbit_amqqueue, lookup, [QName])), |
| 103 | + |
| 104 | + ?assertMatch({ok, _}, rabbit_ct_broker_helpers:rpc(Config, 0, rabbit_amqqueue, delete_with, [QName, false, false, ?INTERNAL_USER])), |
| 105 | + |
| 106 | + ?assertMatch({error, not_found}, rabbit_ct_broker_helpers:rpc(Config, 0, rabbit_amqqueue, lookup, [QName])), |
| 107 | + |
| 108 | + ok. |
| 109 | + |
| 110 | +%% Utility |
| 111 | + |
| 112 | +queue_name(Config, Name) -> |
| 113 | + Name1 = iolist_to_binary(rabbit_ct_helpers:config_to_testcase_name(Config, Name)), |
| 114 | + queue_name(Name1). |
| 115 | + |
| 116 | +queue_name(Name) -> |
| 117 | + rabbit_misc:r(<<"/">>, queue, Name). |
0 commit comments