Skip to content

Commit 88eec97

Browse files
Ayanda-Dmergify[bot]
authored andcommitted
test plugin list supressed warnings, refs: #10865 and #10870
(cherry picked from commit 9391e48)
1 parent f5ade27 commit 88eec97

File tree

3 files changed

+127
-2
lines changed

3 files changed

+127
-2
lines changed

deps/rabbitmq_cli/lib/rabbitmq/cli/plugins/commands/list_command.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ defmodule RabbitMQ.CLI.Plugins.Commands.ListCommand do
122122
["--verbose", "output more information"],
123123
[
124124
"--minimal",
125-
"only print plugin names. Most useful in compbination with --silent and --enabled."
125+
"only print plugin names. Most useful in combination with --silent and --enabled."
126126
],
127127
["--enabled", "only list enabled plugins"],
128128
["--implicitly-enabled", "include plugins enabled as dependencies of other plugins"]

deps/rabbitmq_cli/lib/rabbitmq/cli/plugins/plugins_helpers.ex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,9 @@ defmodule RabbitMQ.CLI.Plugins.Helpers do
195195
all_plugin_names = Enum.map(all, &plugin_name/1)
196196
missing = MapSet.difference(MapSet.new(plugins), MapSet.new(all_plugin_names))
197197

198-
case Enum.empty?(missing) do
198+
hard_write = Map.get(opts, :hard_write, false)
199+
200+
case Enum.empty?(missing) or hard_write do
199201
true ->
200202
case :rabbit_file.write_term_file(to_charlist(plugins_file), [plugins]) do
201203
:ok ->

deps/rabbitmq_cli/test/plugins/list_plugins_command_test.exs

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
defmodule ListPluginsCommandTest do
88
use ExUnit.Case, async: false
99
import TestHelper
10+
import ExUnit.CaptureIO
1011

1112
@command RabbitMQ.CLI.Plugins.Commands.ListCommand
1213

@@ -444,4 +445,126 @@ defmodule ListPluginsCommandTest do
444445

445446
assert_plugin_states(actual_plugins2, expected_plugins2)
446447
end
448+
449+
test "run: lists all plugins with missing plugins warning control using --silent", context do
450+
opts =
451+
context[:opts]
452+
|> Map.put_new(:silent, true)
453+
|> Map.put_new(:hard_write, true)
454+
455+
context = Map.replace(context, :opts, opts)
456+
457+
missing_plugin = :rabbitmq_non_existent
458+
459+
reset_enabled_plugins_to_preconfigured_defaults(context)
460+
461+
set_enabled_plugins(
462+
[:rabbitmq_federation, missing_plugin],
463+
:online,
464+
context[:opts][:node],
465+
context[:opts]
466+
)
467+
468+
on_exit(fn ->
469+
opts =
470+
context[:opts]
471+
|> Map.delete(:silent)
472+
|> Map.delete(:hard_write)
473+
474+
context = Map.replace(context, :opts, opts)
475+
476+
set_enabled_plugins(
477+
[:rabbitmq_stomp, :rabbitmq_federation],
478+
:online,
479+
context[:opts][:node],
480+
context[:opts]
481+
)
482+
end)
483+
484+
expected_plugins = [
485+
%{name: :rabbitmq_federation, enabled: :enabled, running: true},
486+
%{name: :rabbitmq_stomp, enabled: :not_enabled, running: false}
487+
]
488+
489+
opts = context[:opts]
490+
491+
assert capture_io(fn ->
492+
%{
493+
plugins: actual_plugins
494+
} = @command.run([".*"], opts)
495+
496+
assert_plugin_states(actual_plugins, expected_plugins)
497+
end) =~ ~s//
498+
499+
opts = Map.replace(opts, :silent, false)
500+
501+
assert capture_io(fn ->
502+
%{
503+
plugins: actual_plugins
504+
} = @command.run([".*"], opts)
505+
506+
assert_plugin_states(actual_plugins, expected_plugins)
507+
end) =~ ~s/WARNING - plugins currently enabled but missing: #{missing_plugin}\n/
508+
end
509+
510+
test "run: lists all plugins with missing plugins warning control using --quiet", context do
511+
opts =
512+
context[:opts]
513+
|> Map.put_new(:quiet, true)
514+
|> Map.put_new(:hard_write, true)
515+
516+
context = Map.replace(context, :opts, opts)
517+
518+
missing_plugin = :rabbitmq_non_existent
519+
520+
reset_enabled_plugins_to_preconfigured_defaults(context)
521+
522+
set_enabled_plugins(
523+
[:rabbitmq_federation, missing_plugin],
524+
:online,
525+
context[:opts][:node],
526+
context[:opts]
527+
)
528+
529+
on_exit(fn ->
530+
opts =
531+
context[:opts]
532+
|> Map.delete(:quiet)
533+
|> Map.delete(:hard_write)
534+
535+
context = Map.replace(context, :opts, opts)
536+
537+
set_enabled_plugins(
538+
[:rabbitmq_stomp, :rabbitmq_federation],
539+
:online,
540+
context[:opts][:node],
541+
context[:opts]
542+
)
543+
end)
544+
545+
expected_plugins = [
546+
%{name: :rabbitmq_federation, enabled: :enabled, running: true},
547+
%{name: :rabbitmq_stomp, enabled: :not_enabled, running: false}
548+
]
549+
550+
opts = context[:opts]
551+
552+
assert capture_io(fn ->
553+
%{
554+
plugins: actual_plugins
555+
} = @command.run([".*"], opts)
556+
557+
assert_plugin_states(actual_plugins, expected_plugins)
558+
end) =~ ~s//
559+
560+
opts = Map.replace(opts, :quiet, false)
561+
562+
assert capture_io(fn ->
563+
%{
564+
plugins: actual_plugins
565+
} = @command.run([".*"], opts)
566+
567+
assert_plugin_states(actual_plugins, expected_plugins)
568+
end) =~ ~s/WARNING - plugins currently enabled but missing: #{missing_plugin}\n/
569+
end
447570
end

0 commit comments

Comments
 (0)