Skip to content

Commit

Permalink
test plugin list supressed warnings, refs: #10865 and #10870
Browse files Browse the repository at this point in the history
(cherry picked from commit 9391e48)
  • Loading branch information
Ayanda-D authored and mergify[bot] committed Mar 28, 2024
1 parent f5ade27 commit 88eec97
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 2 deletions.
Expand Up @@ -122,7 +122,7 @@ defmodule RabbitMQ.CLI.Plugins.Commands.ListCommand do
["--verbose", "output more information"],
[
"--minimal",
"only print plugin names. Most useful in compbination with --silent and --enabled."
"only print plugin names. Most useful in combination with --silent and --enabled."
],
["--enabled", "only list enabled plugins"],
["--implicitly-enabled", "include plugins enabled as dependencies of other plugins"]
Expand Down
Expand Up @@ -195,7 +195,9 @@ defmodule RabbitMQ.CLI.Plugins.Helpers do
all_plugin_names = Enum.map(all, &plugin_name/1)
missing = MapSet.difference(MapSet.new(plugins), MapSet.new(all_plugin_names))

case Enum.empty?(missing) do
hard_write = Map.get(opts, :hard_write, false)

case Enum.empty?(missing) or hard_write do
true ->
case :rabbit_file.write_term_file(to_charlist(plugins_file), [plugins]) do
:ok ->
Expand Down
123 changes: 123 additions & 0 deletions deps/rabbitmq_cli/test/plugins/list_plugins_command_test.exs
Expand Up @@ -7,6 +7,7 @@
defmodule ListPluginsCommandTest do
use ExUnit.Case, async: false
import TestHelper
import ExUnit.CaptureIO

@command RabbitMQ.CLI.Plugins.Commands.ListCommand

Expand Down Expand Up @@ -444,4 +445,126 @@ defmodule ListPluginsCommandTest do

assert_plugin_states(actual_plugins2, expected_plugins2)
end

test "run: lists all plugins with missing plugins warning control using --silent", context do
opts =
context[:opts]
|> Map.put_new(:silent, true)
|> Map.put_new(:hard_write, true)

context = Map.replace(context, :opts, opts)

missing_plugin = :rabbitmq_non_existent

reset_enabled_plugins_to_preconfigured_defaults(context)

set_enabled_plugins(
[:rabbitmq_federation, missing_plugin],
:online,
context[:opts][:node],
context[:opts]
)

on_exit(fn ->
opts =
context[:opts]
|> Map.delete(:silent)
|> Map.delete(:hard_write)

context = Map.replace(context, :opts, opts)

set_enabled_plugins(
[:rabbitmq_stomp, :rabbitmq_federation],
:online,
context[:opts][:node],
context[:opts]
)
end)

expected_plugins = [
%{name: :rabbitmq_federation, enabled: :enabled, running: true},
%{name: :rabbitmq_stomp, enabled: :not_enabled, running: false}
]

opts = context[:opts]

assert capture_io(fn ->
%{
plugins: actual_plugins
} = @command.run([".*"], opts)

assert_plugin_states(actual_plugins, expected_plugins)
end) =~ ~s//

opts = Map.replace(opts, :silent, false)

assert capture_io(fn ->
%{
plugins: actual_plugins
} = @command.run([".*"], opts)

assert_plugin_states(actual_plugins, expected_plugins)
end) =~ ~s/WARNING - plugins currently enabled but missing: #{missing_plugin}\n/
end

test "run: lists all plugins with missing plugins warning control using --quiet", context do
opts =
context[:opts]
|> Map.put_new(:quiet, true)
|> Map.put_new(:hard_write, true)

context = Map.replace(context, :opts, opts)

missing_plugin = :rabbitmq_non_existent

reset_enabled_plugins_to_preconfigured_defaults(context)

set_enabled_plugins(
[:rabbitmq_federation, missing_plugin],
:online,
context[:opts][:node],
context[:opts]
)

on_exit(fn ->
opts =
context[:opts]
|> Map.delete(:quiet)
|> Map.delete(:hard_write)

context = Map.replace(context, :opts, opts)

set_enabled_plugins(
[:rabbitmq_stomp, :rabbitmq_federation],
:online,
context[:opts][:node],
context[:opts]
)
end)

expected_plugins = [
%{name: :rabbitmq_federation, enabled: :enabled, running: true},
%{name: :rabbitmq_stomp, enabled: :not_enabled, running: false}
]

opts = context[:opts]

assert capture_io(fn ->
%{
plugins: actual_plugins
} = @command.run([".*"], opts)

assert_plugin_states(actual_plugins, expected_plugins)
end) =~ ~s//

opts = Map.replace(opts, :quiet, false)

assert capture_io(fn ->
%{
plugins: actual_plugins
} = @command.run([".*"], opts)

assert_plugin_states(actual_plugins, expected_plugins)
end) =~ ~s/WARNING - plugins currently enabled but missing: #{missing_plugin}\n/
end
end

0 comments on commit 88eec97

Please sign in to comment.