|
| 1 | +## This Source Code Form is subject to the terms of the Mozilla Public |
| 2 | +## License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 | +## file, You can obtain one at https://mozilla.org/MPL/2.0/. |
| 4 | +## |
| 5 | +## Copyright (c) 2007-2026 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. All rights reserved. |
| 6 | + |
| 7 | +defmodule ListChannelInterceptorsCommandTest do |
| 8 | + use ExUnit.Case, async: false |
| 9 | + import TestHelper |
| 10 | + |
| 11 | + @command RabbitMQ.CLI.Ctl.Commands.ListChannelInterceptorsCommand |
| 12 | + |
| 13 | + setup_all do |
| 14 | + RabbitMQ.CLI.Core.Distribution.start() |
| 15 | + |
| 16 | + :ok |
| 17 | + end |
| 18 | + |
| 19 | + setup context do |
| 20 | + { |
| 21 | + :ok, |
| 22 | + opts: %{ |
| 23 | + node: get_rabbit_hostname(), |
| 24 | + timeout: context[:test_timeout] || :infinity |
| 25 | + } |
| 26 | + } |
| 27 | + end |
| 28 | + |
| 29 | + test "merge_defaults: adds table_headers true to opts", context do |
| 30 | + {args, opts} = @command.merge_defaults([], context[:opts]) |
| 31 | + assert args == [] |
| 32 | + assert opts[:table_headers] == true |
| 33 | + end |
| 34 | + |
| 35 | + test "validate: accepts no positional arguments", context do |
| 36 | + assert @command.validate([], context[:opts]) == :ok |
| 37 | + end |
| 38 | + |
| 39 | + test "validate: rejects any positional arguments", context do |
| 40 | + assert @command.validate(["extra"], context[:opts]) == |
| 41 | + {:validation_failure, :too_many_args} |
| 42 | + end |
| 43 | + |
| 44 | + test "run: on a bad RabbitMQ node, returns a badrpc" do |
| 45 | + opts = %{node: :jake@thedog, timeout: 200} |
| 46 | + assert match?({:badrpc, _}, @command.run([], opts)) |
| 47 | + end |
| 48 | + |
| 49 | + @tag test_timeout: :infinity |
| 50 | + test "run: with no interceptors registered, returns an empty list", context do |
| 51 | + result = @command.run([], context[:opts]) |
| 52 | + assert result == [] |
| 53 | + end |
| 54 | + |
| 55 | + @tag test_timeout: :infinity |
| 56 | + test "run: registered interceptors are listed with applies_to joined as a string", context do |
| 57 | + node = get_rabbit_hostname() |
| 58 | + |
| 59 | + :ok = |
| 60 | + :rabbit_misc.rpc_call( |
| 61 | + node, |
| 62 | + :rabbit_registry, |
| 63 | + :register, |
| 64 | + [:channel_interceptor, <<"test interceptor">>, :dummy_interceptor] |
| 65 | + ) |
| 66 | + |
| 67 | + try do |
| 68 | + result = @command.run([], context[:opts]) |
| 69 | + assert is_list(result) |
| 70 | + interceptor = Enum.find(result, fn info -> info[:name] == :dummy_interceptor end) |
| 71 | + assert interceptor != nil |
| 72 | + assert is_binary(interceptor[:applies_to]) |
| 73 | + assert is_integer(interceptor[:priority]) |
| 74 | + after |
| 75 | + :rabbit_misc.rpc_call( |
| 76 | + node, |
| 77 | + :rabbit_registry, |
| 78 | + :unregister, |
| 79 | + [:channel_interceptor, <<"test interceptor">>] |
| 80 | + ) |
| 81 | + end |
| 82 | + end |
| 83 | + |
| 84 | + test "banner: returns the expected string", context do |
| 85 | + assert @command.banner([], context[:opts]) == "Listing channel interceptors ..." |
| 86 | + end |
| 87 | +end |
0 commit comments