summaryrefslogtreecommitdiff
path: root/deps/rabbitmq_cli/test/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'deps/rabbitmq_cli/test/plugins')
-rw-r--r--deps/rabbitmq_cli/test/plugins/directories_command_test.exs103
-rw-r--r--deps/rabbitmq_cli/test/plugins/disable_plugins_command_test.exs187
-rw-r--r--deps/rabbitmq_cli/test/plugins/enable_plugins_command_test.exs243
-rw-r--r--deps/rabbitmq_cli/test/plugins/is_enabled_command_test.exs103
-rw-r--r--deps/rabbitmq_cli/test/plugins/list_plugins_command_test.exs235
-rw-r--r--deps/rabbitmq_cli/test/plugins/plugins_formatter_test.exs45
-rw-r--r--deps/rabbitmq_cli/test/plugins/set_plugins_command_test.exs157
7 files changed, 1073 insertions, 0 deletions
diff --git a/deps/rabbitmq_cli/test/plugins/directories_command_test.exs b/deps/rabbitmq_cli/test/plugins/directories_command_test.exs
new file mode 100644
index 0000000000..cae418717a
--- /dev/null
+++ b/deps/rabbitmq_cli/test/plugins/directories_command_test.exs
@@ -0,0 +1,103 @@
+## This Source Code Form is subject to the terms of the Mozilla Public
+## License, v. 2.0. If a copy of the MPL was not distributed with this
+## file, You can obtain one at https://mozilla.org/MPL/2.0/.
+##
+## Copyright (c) 2007-2020 VMware, Inc. or its affiliates. All rights reserved.
+
+defmodule DirectoriesCommandTest do
+ use ExUnit.Case, async: false
+ import TestHelper
+
+ @command RabbitMQ.CLI.Plugins.Commands.DirectoriesCommand
+
+ setup_all do
+ RabbitMQ.CLI.Core.Distribution.start()
+ node = get_rabbit_hostname()
+
+ {:ok, plugins_file} = :rabbit_misc.rpc_call(node,
+ :application, :get_env,
+ [:rabbit, :enabled_plugins_file])
+ {:ok, plugins_dir} = :rabbit_misc.rpc_call(node,
+ :application, :get_env,
+ [:rabbit, :plugins_dir])
+ {:ok, plugins_expand_dir} = :rabbit_misc.rpc_call(node,
+ :application, :get_env,
+ [:rabbit, :plugins_expand_dir])
+
+ rabbitmq_home = :rabbit_misc.rpc_call(node, :code, :lib_dir, [:rabbit])
+
+ {:ok, opts: %{
+ plugins_file: plugins_file,
+ plugins_dir: plugins_dir,
+ plugins_expand_dir: plugins_expand_dir,
+ rabbitmq_home: rabbitmq_home,
+ }}
+ end
+
+ setup context do
+ {
+ :ok,
+ opts: Map.merge(context[:opts], %{
+ node: get_rabbit_hostname(),
+ timeout: 1000
+ })
+ }
+ end
+
+ test "validate: providing no arguments passes validation", context do
+ assert @command.validate([], context[:opts]) == :ok
+ end
+
+ test "validate: providing --online passes validation", context do
+ assert @command.validate([], Map.merge(%{online: true}, context[:opts])) == :ok
+ end
+
+ test "validate: providing --offline passes validation", context do
+ assert @command.validate([], Map.merge(%{offline: true}, context[:opts])) == :ok
+ end
+
+ test "validate: providing any arguments fails validation", context do
+ assert @command.validate(["a", "b", "c"], context[:opts]) ==
+ {:validation_failure, :too_many_args}
+ end
+
+ test "validate: setting both --online and --offline to false fails validation", context do
+ assert @command.validate([], Map.merge(context[:opts], %{online: false, offline: false})) ==
+ {:validation_failure, {:bad_argument, "Cannot set online and offline to false"}}
+ end
+
+ test "validate: setting both --online and --offline to true fails validation", context do
+ assert @command.validate([], Map.merge(context[:opts], %{online: true, offline: true})) ==
+ {:validation_failure, {:bad_argument, "Cannot set both online and offline"}}
+ end
+
+ test "validate_execution_environment: when --offline is used, specifying a non-existent enabled_plugins_file passes validation", context do
+ opts = context[:opts] |> Map.merge(%{offline: true, enabled_plugins_file: "none"})
+ assert @command.validate_execution_environment([], opts) == :ok
+ end
+
+ test "validate_execution_environment: when --offline is used, specifying a non-existent plugins_dir fails validation", context do
+ opts = context[:opts] |> Map.merge(%{offline: true, plugins_dir: "none"})
+ assert @command.validate_execution_environment([], opts) == {:validation_failure, :plugins_dir_does_not_exist}
+ end
+
+ test "validate_execution_environment: when --online is used, specifying a non-existent enabled_plugins_file passes validation", context do
+ opts = context[:opts] |> Map.merge(%{online: true, enabled_plugins_file: "none"})
+ assert @command.validate_execution_environment([], opts) == :ok
+ end
+
+ test "validate_execution_environment: when --online is used, specifying a non-existent plugins_dir passes validation", context do
+ opts = context[:opts] |> Map.merge(%{online: true, plugins_dir: "none"})
+ assert @command.validate_execution_environment([], opts) == :ok
+ end
+
+
+ test "run: when --online is used, lists plugin directories", context do
+ opts = Map.merge(context[:opts], %{online: true})
+ dirs = %{plugins_dir: to_string(Map.get(opts, :plugins_dir)),
+ plugins_expand_dir: to_string(Map.get(opts, :plugins_expand_dir)),
+ enabled_plugins_file: to_string(Map.get(opts, :plugins_file))}
+
+ assert @command.run([], opts) == {:ok, dirs}
+ end
+end
diff --git a/deps/rabbitmq_cli/test/plugins/disable_plugins_command_test.exs b/deps/rabbitmq_cli/test/plugins/disable_plugins_command_test.exs
new file mode 100644
index 0000000000..dc5d92e090
--- /dev/null
+++ b/deps/rabbitmq_cli/test/plugins/disable_plugins_command_test.exs
@@ -0,0 +1,187 @@
+## This Source Code Form is subject to the terms of the Mozilla Public
+## License, v. 2.0. If a copy of the MPL was not distributed with this
+## file, You can obtain one at https://mozilla.org/MPL/2.0/.
+##
+## Copyright (c) 2007-2020 VMware, Inc. or its affiliates. All rights reserved.
+
+defmodule DisablePluginsCommandTest do
+ use ExUnit.Case, async: false
+ import TestHelper
+
+ alias RabbitMQ.CLI.Core.ExitCodes
+
+ @command RabbitMQ.CLI.Plugins.Commands.DisableCommand
+
+ setup_all do
+ RabbitMQ.CLI.Core.Distribution.start()
+ node = get_rabbit_hostname()
+
+ {:ok, plugins_file} = :rabbit_misc.rpc_call(node,
+ :application, :get_env,
+ [:rabbit, :enabled_plugins_file])
+ {:ok, plugins_dir} = :rabbit_misc.rpc_call(node,
+ :application, :get_env,
+ [:rabbit, :plugins_dir])
+ rabbitmq_home = :rabbit_misc.rpc_call(node, :code, :lib_dir, [:rabbit])
+
+ IO.puts("plugins disable tests default env: enabled plugins = #{plugins_file}, plugins dir = #{plugins_dir}, RabbitMQ home directory = #{rabbitmq_home}")
+
+ {:ok, [enabled_plugins]} = :file.consult(plugins_file)
+ IO.puts("plugins disable tests will assume tnat #{Enum.join(enabled_plugins, ",")} is the list of enabled plugins to revert to")
+
+ opts = %{enabled_plugins_file: plugins_file,
+ plugins_dir: plugins_dir,
+ rabbitmq_home: rabbitmq_home,
+ online: false, offline: false,
+ all: false}
+
+ on_exit(fn ->
+ set_enabled_plugins(enabled_plugins, :online, get_rabbit_hostname(), opts)
+ end)
+
+ {:ok, opts: opts}
+ end
+
+ setup context do
+ set_enabled_plugins([:rabbitmq_stomp, :rabbitmq_federation],
+ :online,
+ get_rabbit_hostname(),
+ context[:opts])
+
+
+ {
+ :ok,
+ opts: Map.merge(context[:opts], %{
+ node: get_rabbit_hostname(),
+ timeout: 1000
+ })
+ }
+ end
+
+ test "validate: specifying both --online and --offline is reported as invalid", context do
+ assert match?(
+ {:validation_failure, {:bad_argument, _}},
+ @command.validate(["a"], Map.merge(context[:opts], %{online: true, offline: true}))
+ )
+ end
+
+ test "validate: not specifying plugins to enable is reported as invalid", context do
+ assert match?(
+ {:validation_failure, :not_enough_args},
+ @command.validate([], Map.merge(context[:opts], %{online: true, offline: false}))
+ )
+ end
+
+ test "validate_execution_environment: specifying a non-existent enabled_plugins_file is fine", context do
+ assert @command.validate_execution_environment(["a"], Map.merge(context[:opts], %{enabled_plugins_file: "none"})) == :ok
+ end
+
+ test "validate_execution_environment: specifying a non-existent plugins_dir is reported as an error", context do
+ assert @command.validate_execution_environment(["a"], Map.merge(context[:opts], %{plugins_dir: "none"})) ==
+ {:validation_failure, :plugins_dir_does_not_exist}
+ end
+
+ test "node is inaccessible, writes out enabled plugins file and returns implicitly enabled plugin list", context do
+ assert {:stream, test_stream} =
+ @command.run(["rabbitmq_stomp"], Map.merge(context[:opts], %{node: :nonode}))
+ assert [[:rabbitmq_federation],
+ %{mode: :offline, disabled: [:rabbitmq_stomp], set: [:rabbitmq_federation]}] ==
+ Enum.to_list(test_stream)
+ assert {:ok, [[:rabbitmq_federation]]} == :file.consult(context[:opts][:enabled_plugins_file])
+ assert [:amqp_client, :rabbitmq_federation, :rabbitmq_stomp] ==
+ Enum.sort(:rabbit_misc.rpc_call(context[:opts][:node], :rabbit_plugins, :active, []))
+ end
+
+ test "in offline mode, writes out enabled plugins and reports implicitly enabled plugin list", context do
+ assert {:stream, test_stream} = @command.run(["rabbitmq_stomp"], Map.merge(context[:opts], %{offline: true, online: false}))
+ assert [[:rabbitmq_federation],
+ %{mode: :offline, disabled: [:rabbitmq_stomp], set: [:rabbitmq_federation]}] == Enum.to_list(test_stream)
+ assert {:ok, [[:rabbitmq_federation]]} == :file.consult(context[:opts][:enabled_plugins_file])
+ assert [:amqp_client, :rabbitmq_federation, :rabbitmq_stomp] ==
+ Enum.sort(:rabbit_misc.rpc_call(context[:opts][:node], :rabbit_plugins, :active, []))
+ end
+
+ test "in offline mode , removes implicitly enabled plugins when last explicitly enabled one is removed", context do
+ assert {:stream, test_stream0} =
+ @command.run(["rabbitmq_federation"], Map.merge(context[:opts], %{offline: true, online: false}))
+ assert [[:rabbitmq_stomp],
+ %{mode: :offline, disabled: [:rabbitmq_federation], set: [:rabbitmq_stomp]}] == Enum.to_list(test_stream0)
+ assert {:ok, [[:rabbitmq_stomp]]} == :file.consult(context[:opts][:enabled_plugins_file])
+
+ assert {:stream, test_stream1} =
+ @command.run(["rabbitmq_stomp"], Map.merge(context[:opts], %{offline: true, online: false}))
+ assert [[],
+ %{mode: :offline, disabled: [:rabbitmq_stomp], set: []}] ==
+ Enum.to_list(test_stream1)
+ assert {:ok, [[]]} = :file.consult(context[:opts][:enabled_plugins_file])
+ end
+
+ test "updates plugin list and stops disabled plugins", context do
+ assert {:stream, test_stream0} =
+ @command.run(["rabbitmq_stomp"], context[:opts])
+ assert [[:rabbitmq_federation],
+ %{mode: :online,
+ started: [], stopped: [:rabbitmq_stomp],
+ disabled: [:rabbitmq_stomp],
+ set: [:rabbitmq_federation]}] ==
+ Enum.to_list(test_stream0)
+ assert {:ok, [[:rabbitmq_federation]]} == :file.consult(context[:opts][:enabled_plugins_file])
+ assert [:amqp_client, :rabbitmq_federation] ==
+ Enum.sort(:rabbit_misc.rpc_call(context[:opts][:node], :rabbit_plugins, :active, []))
+
+ assert {:stream, test_stream1} =
+ @command.run(["rabbitmq_federation"], context[:opts])
+ assert [[],
+ %{mode: :online,
+ started: [], stopped: [:rabbitmq_federation],
+ disabled: [:rabbitmq_federation],
+ set: []}] ==
+ Enum.to_list(test_stream1)
+ assert {:ok, [[]]} == :file.consult(context[:opts][:enabled_plugins_file])
+ assert Enum.empty?(Enum.sort(:rabbit_misc.rpc_call(context[:opts][:node], :rabbit_plugins, :active, [])))
+ end
+
+ test "can disable multiple plugins at once", context do
+ assert {:stream, test_stream} =
+ @command.run(["rabbitmq_stomp", "rabbitmq_federation"], context[:opts])
+ assert [[],
+ %{mode: :online,
+ started: [], stopped: [:rabbitmq_federation, :rabbitmq_stomp],
+ disabled: [:rabbitmq_federation, :rabbitmq_stomp],
+ set: []}] ==
+ Enum.to_list(test_stream)
+ assert {:ok, [[]]} == :file.consult(context[:opts][:enabled_plugins_file])
+ assert Enum.empty?(Enum.sort(:rabbit_misc.rpc_call(context[:opts][:node], :rabbit_plugins, :active, [])))
+ end
+
+ test "disabling a dependency disables all plugins that depend on it", context do
+ assert {:stream, test_stream} = @command.run(["amqp_client"], context[:opts])
+ assert [[],
+ %{mode: :online,
+ started: [], stopped: [:rabbitmq_federation, :rabbitmq_stomp],
+ disabled: [:rabbitmq_federation, :rabbitmq_stomp],
+ set: []}] ==
+ Enum.to_list(test_stream)
+ assert {:ok, [[]]} == :file.consult(context[:opts][:enabled_plugins_file])
+ assert Enum.empty?(Enum.sort(:rabbit_misc.rpc_call(context[:opts][:node], :rabbit_plugins, :active, [])))
+ end
+
+ test "formats enabled plugins mismatch errors", context do
+ err = {:enabled_plugins_mismatch, '/tmp/a/cli/path', '/tmp/a/server/path'}
+ assert {:error, ExitCodes.exit_dataerr(),
+ "Could not update enabled plugins file at /tmp/a/cli/path: target node #{context[:opts][:node]} uses a different path (/tmp/a/server/path)"}
+ == @command.output({:error, err}, context[:opts])
+ end
+
+ test "formats enabled plugins write errors", context do
+ err1 = {:cannot_write_enabled_plugins_file, "/tmp/a/path", :eacces}
+ assert {:error, ExitCodes.exit_dataerr(),
+ "Could not update enabled plugins file at /tmp/a/path: the file does not exist or permission was denied (EACCES)"} ==
+ @command.output({:error, err1}, context[:opts])
+
+ err2 = {:cannot_write_enabled_plugins_file, "/tmp/a/path", :enoent}
+ assert {:error, ExitCodes.exit_dataerr(),
+ "Could not update enabled plugins file at /tmp/a/path: the file does not exist (ENOENT)"} ==
+ @command.output({:error, err2}, context[:opts])
+ end
+end
diff --git a/deps/rabbitmq_cli/test/plugins/enable_plugins_command_test.exs b/deps/rabbitmq_cli/test/plugins/enable_plugins_command_test.exs
new file mode 100644
index 0000000000..09aaf38351
--- /dev/null
+++ b/deps/rabbitmq_cli/test/plugins/enable_plugins_command_test.exs
@@ -0,0 +1,243 @@
+## This Source Code Form is subject to the terms of the Mozilla Public
+## License, v. 2.0. If a copy of the MPL was not distributed with this
+## file, You can obtain one at https://mozilla.org/MPL/2.0/.
+##
+## Copyright (c) 2007-2020 VMware, Inc. or its affiliates. All rights reserved.
+
+defmodule EnablePluginsCommandTest do
+ use ExUnit.Case, async: false
+ import TestHelper
+
+ alias RabbitMQ.CLI.Core.ExitCodes
+
+ @command RabbitMQ.CLI.Plugins.Commands.EnableCommand
+
+ setup_all do
+ RabbitMQ.CLI.Core.Distribution.start()
+ node = get_rabbit_hostname()
+
+ {:ok, plugins_file} = :rabbit_misc.rpc_call(node,
+ :application, :get_env,
+ [:rabbit, :enabled_plugins_file])
+ {:ok, plugins_dir} = :rabbit_misc.rpc_call(node,
+ :application, :get_env,
+ [:rabbit, :plugins_dir])
+ rabbitmq_home = :rabbit_misc.rpc_call(node, :code, :lib_dir, [:rabbit])
+
+ IO.puts("plugins enable tests default env: enabled plugins = #{plugins_file}, plugins dir = #{plugins_dir}, RabbitMQ home directory = #{rabbitmq_home}")
+
+ {:ok, [enabled_plugins]} = :file.consult(plugins_file)
+ IO.puts("plugins enable tests will assume tnat #{Enum.join(enabled_plugins, ",")} is the list of enabled plugins to revert to")
+
+ opts = %{enabled_plugins_file: plugins_file,
+ plugins_dir: plugins_dir,
+ rabbitmq_home: rabbitmq_home,
+ online: false, offline: false,
+ all: false}
+
+ on_exit(fn ->
+ set_enabled_plugins(enabled_plugins, :online, get_rabbit_hostname(), opts)
+ end)
+
+
+ {:ok, opts: opts}
+ end
+
+ setup context do
+ set_enabled_plugins([:rabbitmq_stomp, :rabbitmq_federation],
+ :online,
+ get_rabbit_hostname(),
+ context[:opts])
+
+ {
+ :ok,
+ opts: Map.merge(context[:opts], %{
+ node: get_rabbit_hostname(),
+ timeout: 1000
+ })
+ }
+ end
+
+ test "validate: specifying both --online and --offline is reported as invalid", context do
+ assert match?(
+ {:validation_failure, {:bad_argument, _}},
+ @command.validate(["a"], Map.merge(context[:opts], %{online: true, offline: true}))
+ )
+ end
+
+ test "validate: not specifying any plugins to enable is reported as invalid", context do
+ assert match?(
+ {:validation_failure, :not_enough_args},
+ @command.validate([], Map.merge(context[:opts], %{online: true, offline: false}))
+ )
+ end
+
+ test "validate_execution_environment: specifying a non-existent enabled_plugins_file is fine", context do
+ assert @command.validate_execution_environment(["a"], Map.merge(context[:opts], %{enabled_plugins_file: "none"})) == :ok
+ end
+
+ test "validate_execution_environment: specifying a non-existent plugins_dir is reported as an error", context do
+ assert @command.validate_execution_environment(["a"], Map.merge(context[:opts], %{plugins_dir: "none"})) ==
+ {:validation_failure, :plugins_dir_does_not_exist}
+ end
+
+ test "if node is inaccessible, writes enabled plugins file and reports implicitly enabled plugin list", context do
+ # Clears enabled plugins file
+ set_enabled_plugins([], :offline, :nonode, context[:opts])
+
+ assert {:stream, test_stream} =
+ @command.run(["rabbitmq_stomp"], Map.merge(context[:opts], %{node: :nonode}))
+ assert [[:rabbitmq_stomp],
+ %{mode: :offline, enabled: [:rabbitmq_stomp], set: [:rabbitmq_stomp]}] ==
+ Enum.to_list(test_stream)
+ check_plugins_enabled([:rabbitmq_stomp], context)
+ assert [:amqp_client, :rabbitmq_federation, :rabbitmq_stomp] ==
+ currently_active_plugins(context)
+ end
+
+ test "in offline mode, writes enabled plugins and reports implicitly enabled plugin list", context do
+ # Clears enabled plugins file
+ set_enabled_plugins([], :offline, :nonode, context[:opts])
+
+ assert {:stream, test_stream} =
+ @command.run(["rabbitmq_stomp"], Map.merge(context[:opts], %{offline: true, online: false}))
+ assert [[:rabbitmq_stomp],
+ %{mode: :offline, enabled: [:rabbitmq_stomp], set: [:rabbitmq_stomp]}] ==
+ Enum.to_list(test_stream)
+ check_plugins_enabled([:rabbitmq_stomp], context)
+ assert_equal_sets(
+ [:amqp_client, :rabbitmq_federation, :rabbitmq_stomp],
+ currently_active_plugins(context))
+ end
+
+ test "adds additional plugins to those already enabled", context do
+ # Clears enabled plugins file
+ set_enabled_plugins([], :offline, :nonode, context[:opts])
+
+ assert {:stream, test_stream0} =
+ @command.run(["rabbitmq_stomp"], Map.merge(context[:opts], %{offline: true, online: false}))
+ assert [[:rabbitmq_stomp],
+ %{mode: :offline, enabled: [:rabbitmq_stomp], set: [:rabbitmq_stomp]}] ==
+ Enum.to_list(test_stream0)
+ check_plugins_enabled([:rabbitmq_stomp], context)
+ assert {:stream, test_stream1} =
+ @command.run(["rabbitmq_federation"], Map.merge(context[:opts], %{offline: true, online: false}))
+ assert [[:rabbitmq_federation, :rabbitmq_stomp],
+ %{mode: :offline, enabled: [:rabbitmq_federation],
+ set: [:rabbitmq_federation, :rabbitmq_stomp]}] ==
+ Enum.to_list(test_stream1)
+ check_plugins_enabled([:rabbitmq_stomp, :rabbitmq_federation], context)
+ end
+
+ test "updates plugin list and starts newly enabled plugins", context do
+ # Clears enabled plugins file and stop all plugins
+ set_enabled_plugins([], :online, context[:opts][:node], context[:opts])
+
+ assert {:stream, test_stream0} =
+ @command.run(["rabbitmq_stomp"], context[:opts])
+ assert [[:rabbitmq_stomp],
+ %{mode: :online,
+ started: [:rabbitmq_stomp], stopped: [],
+ enabled: [:rabbitmq_stomp],
+ set: [:rabbitmq_stomp]}] ==
+ Enum.to_list(test_stream0)
+
+ check_plugins_enabled([:rabbitmq_stomp], context)
+ assert_equal_sets([:amqp_client, :rabbitmq_stomp], currently_active_plugins(context))
+
+ {:stream, test_stream1} =
+ @command.run(["rabbitmq_federation"], context[:opts])
+ assert [[:rabbitmq_federation, :rabbitmq_stomp],
+ %{mode: :online,
+ started: [:rabbitmq_federation], stopped: [],
+ enabled: [:rabbitmq_federation],
+ set: [:rabbitmq_federation, :rabbitmq_stomp]}] ==
+ Enum.to_list(test_stream1)
+
+ check_plugins_enabled([:rabbitmq_stomp, :rabbitmq_federation], context)
+ assert_equal_sets([:amqp_client, :rabbitmq_federation, :rabbitmq_stomp], currently_active_plugins(context))
+ end
+
+ test "can enable multiple plugins at once", context do
+ # Clears plugins file and stop all plugins
+ set_enabled_plugins([], :online, context[:opts][:node], context[:opts])
+
+ assert {:stream, test_stream} =
+ @command.run(["rabbitmq_stomp", "rabbitmq_federation"], context[:opts])
+ assert [[:rabbitmq_federation, :rabbitmq_stomp],
+ %{mode: :online,
+ started: [:rabbitmq_federation, :rabbitmq_stomp], stopped: [],
+ enabled: [:rabbitmq_federation, :rabbitmq_stomp],
+ set: [:rabbitmq_federation, :rabbitmq_stomp]}] ==
+ Enum.to_list(test_stream)
+ check_plugins_enabled([:rabbitmq_stomp, :rabbitmq_federation], context)
+
+ assert_equal_sets([:amqp_client, :rabbitmq_federation, :rabbitmq_stomp], currently_active_plugins(context))
+ end
+
+ test "does not enable an already implicitly enabled plugin", context do
+ # Clears enabled plugins file and stop all plugins
+ set_enabled_plugins([:rabbitmq_federation], :online, context[:opts][:node], context[:opts])
+ assert {:stream, test_stream} =
+ @command.run(["amqp_client"], context[:opts])
+ assert [[:rabbitmq_federation],
+ %{mode: :online,
+ started: [], stopped: [],
+ enabled: [],
+ set: [:rabbitmq_federation]}] ==
+ Enum.to_list(test_stream)
+ check_plugins_enabled([:rabbitmq_federation], context)
+ assert [:amqp_client, :rabbitmq_federation] ==
+ currently_active_plugins(context)
+
+ end
+
+ test "run: does not enable plugins with unmet version requirements", context do
+ set_enabled_plugins([], :online, context[:opts][:node], context[:opts])
+
+ plugins_directory = fixture_plugins_path("plugins_with_version_requirements")
+ opts = get_opts_with_plugins_directories(context, [plugins_directory])
+ switch_plugins_directories(context[:opts][:plugins_dir], opts[:plugins_dir])
+
+ {:stream, _} =
+ @command.run(["mock_rabbitmq_plugin_for_3_8"], opts)
+ check_plugins_enabled([:mock_rabbitmq_plugin_for_3_8], context)
+
+ # Not changed
+ {:error, _version_error} = @command.run(["mock_rabbitmq_plugin_for_3_7"], opts)
+ check_plugins_enabled([:mock_rabbitmq_plugin_for_3_8], context)
+
+ end
+
+ test "run: does not enable plugins with unmet version requirements even when enabling all plugins", context do
+ set_enabled_plugins([], :online, context[:opts][:node], context[:opts])
+
+ plugins_directory = fixture_plugins_path("plugins_with_version_requirements")
+ opts = get_opts_with_plugins_directories(context, [plugins_directory])
+ opts = Map.merge(opts, %{all: true})
+ switch_plugins_directories(context[:opts][:plugins_dir], opts[:plugins_dir])
+
+ {:error, _version_error} = @command.run([], opts)
+
+ check_plugins_enabled([], context)
+ end
+
+ test "formats enabled plugins mismatch errors", context do
+ err = {:enabled_plugins_mismatch, '/tmp/a/cli/path', '/tmp/a/server/path'}
+ assert {:error, ExitCodes.exit_dataerr(),
+ "Could not update enabled plugins file at /tmp/a/cli/path: target node #{context[:opts][:node]} uses a different path (/tmp/a/server/path)"}
+ == @command.output({:error, err}, context[:opts])
+ end
+
+ test "formats enabled plugins write errors", context do
+ err1 = {:cannot_write_enabled_plugins_file, "/tmp/a/path", :eacces}
+ assert {:error, ExitCodes.exit_dataerr(),
+ "Could not update enabled plugins file at /tmp/a/path: the file does not exist or permission was denied (EACCES)"} ==
+ @command.output({:error, err1}, context[:opts])
+
+ err2 = {:cannot_write_enabled_plugins_file, "/tmp/a/path", :enoent}
+ assert {:error, ExitCodes.exit_dataerr(),
+ "Could not update enabled plugins file at /tmp/a/path: the file does not exist (ENOENT)"} ==
+ @command.output({:error, err2}, context[:opts])
+ end
+end
diff --git a/deps/rabbitmq_cli/test/plugins/is_enabled_command_test.exs b/deps/rabbitmq_cli/test/plugins/is_enabled_command_test.exs
new file mode 100644
index 0000000000..af2900228b
--- /dev/null
+++ b/deps/rabbitmq_cli/test/plugins/is_enabled_command_test.exs
@@ -0,0 +1,103 @@
+## This Source Code Form is subject to the terms of the Mozilla Public
+## License, v. 2.0. If a copy of the MPL was not distributed with this
+## file, You can obtain one at https://mozilla.org/MPL/2.0/.
+##
+## Copyright (c) 2007-2020 VMware, Inc. or its affiliates. All rights reserved.
+
+defmodule PluginIsEnabledCommandTest do
+ use ExUnit.Case, async: false
+ import TestHelper
+
+ @command RabbitMQ.CLI.Plugins.Commands.IsEnabledCommand
+
+ setup_all do
+ RabbitMQ.CLI.Core.Distribution.start()
+ node = get_rabbit_hostname()
+
+ {:ok, plugins_file} = :rabbit_misc.rpc_call(node,
+ :application, :get_env,
+ [:rabbit, :enabled_plugins_file])
+ {:ok, plugins_dir} = :rabbit_misc.rpc_call(node,
+ :application, :get_env,
+ [:rabbit, :plugins_dir])
+ rabbitmq_home = :rabbit_misc.rpc_call(node, :code, :lib_dir, [:rabbit])
+
+ {:ok, [enabled_plugins]} = :file.consult(plugins_file)
+
+ opts = %{enabled_plugins_file: plugins_file,
+ plugins_dir: plugins_dir,
+ rabbitmq_home: rabbitmq_home,
+ online: false, offline: false}
+
+ on_exit(fn ->
+ set_enabled_plugins(enabled_plugins, :online, get_rabbit_hostname(), opts)
+ end)
+
+
+ {:ok, opts: opts}
+ end
+
+ setup context do
+ {
+ :ok,
+ opts: Map.merge(context[:opts], %{
+ node: get_rabbit_hostname(),
+ timeout: 1000
+ })
+ }
+ end
+
+
+
+ test "validate: specifying both --online and --offline is reported as invalid", context do
+ assert match?(
+ {:validation_failure, {:bad_argument, _}},
+ @command.validate(["rabbitmq_stomp"], Map.merge(context[:opts], %{online: true, offline: true}))
+ )
+ end
+
+ test "validate: not specifying any plugins to check is reported as invalid", context do
+ opts = context[:opts] |> Map.merge(%{online: true, offline: false})
+ assert match?({:validation_failure, :not_enough_args}, @command.validate([], opts))
+ end
+
+ test "validate_execution_environment: specifying a non-existent enabled_plugins_file is fine", context do
+ assert @command.validate_execution_environment(["rabbitmq_stomp"],
+ Map.merge(context[:opts], %{online: false,
+ offline: true,
+ enabled_plugins_file: "none"})) == :ok
+ end
+
+ test "validate_execution_environment: specifying a non-existent plugins_dir is reported as an error", context do
+ opts = context[:opts] |> Map.merge(%{online: false,
+ offline: true,
+ plugins_dir: "none"})
+
+ assert @command.validate_execution_environment(["rabbitmq_stomp"], opts) ==
+ {:validation_failure, :plugins_dir_does_not_exist}
+ end
+
+ test "run: when given a single enabled plugin, reports it as such", context do
+ opts = context[:opts] |> Map.merge(%{online: true, offline: false})
+ assert match?({:ok, _},
+ assert @command.run(["rabbitmq_stomp"], opts))
+ end
+
+ test "run: when given a list of actually enabled plugins, reports them as such", context do
+ opts = context[:opts] |> Map.merge(%{online: true, offline: false})
+ assert match?({:ok, _},
+ assert @command.run(["rabbitmq_stomp", "rabbitmq_federation"], opts))
+ end
+
+ test "run: when given a list of non-existent plugins, reports them as not enabled", context do
+ opts = context[:opts] |> Map.merge(%{online: true, offline: false})
+ assert match?({:error, _},
+ assert @command.run(["rabbitmq_xyz", "abc_xyz"], opts))
+ end
+
+ test "run: when given a list with one non-existent plugin, reports the group as not [all] enabled", context do
+ opts = context[:opts] |> Map.merge(%{online: true, offline: false})
+ assert match?({:error, _},
+ assert @command.run(["rabbitmq_stomp", "abc_xyz"], opts))
+ end
+end
diff --git a/deps/rabbitmq_cli/test/plugins/list_plugins_command_test.exs b/deps/rabbitmq_cli/test/plugins/list_plugins_command_test.exs
new file mode 100644
index 0000000000..33d9420435
--- /dev/null
+++ b/deps/rabbitmq_cli/test/plugins/list_plugins_command_test.exs
@@ -0,0 +1,235 @@
+## This Source Code Form is subject to the terms of the Mozilla Public
+## License, v. 2.0. If a copy of the MPL was not distributed with this
+## file, You can obtain one at https://mozilla.org/MPL/2.0/.
+##
+## Copyright (c) 2007-2020 VMware, Inc. or its affiliates. All rights reserved.
+
+defmodule ListPluginsCommandTest do
+ use ExUnit.Case, async: false
+ import TestHelper
+
+ @command RabbitMQ.CLI.Plugins.Commands.ListCommand
+
+ def reset_enabled_plugins_to_preconfigured_defaults(context) do
+ set_enabled_plugins([:rabbitmq_stomp, :rabbitmq_federation],
+ :online,
+ get_rabbit_hostname(), context[:opts])
+ end
+
+ setup_all do
+ RabbitMQ.CLI.Core.Distribution.start()
+ node = get_rabbit_hostname()
+
+ {:ok, plugins_file} = :rabbit_misc.rpc_call(node,
+ :application, :get_env,
+ [:rabbit, :enabled_plugins_file])
+ {:ok, plugins_dir} = :rabbit_misc.rpc_call(node,
+ :application, :get_env,
+ [:rabbit, :plugins_dir])
+ rabbitmq_home = :rabbit_misc.rpc_call(node, :code, :lib_dir, [:rabbit])
+ IO.puts("plugins list tests default env: enabled plugins = #{plugins_file}, plugins dir = #{plugins_dir}, RabbitMQ home directory = #{rabbitmq_home}")
+
+ {:ok, [enabled_plugins]} = :file.consult(plugins_file)
+ IO.puts("plugins list tests will assume tnat #{Enum.join(enabled_plugins, ",")} is the list of enabled plugins to revert to")
+
+ opts = %{enabled_plugins_file: plugins_file,
+ plugins_dir: plugins_dir,
+ rabbitmq_home: rabbitmq_home,
+ minimal: false, verbose: false,
+ enabled: false, implicitly_enabled: false}
+
+ on_exit(fn ->
+ set_enabled_plugins(enabled_plugins, :online, get_rabbit_hostname(), opts)
+ end)
+
+
+ {:ok, opts: opts}
+ end
+
+ setup context do
+ reset_enabled_plugins_to_preconfigured_defaults(context)
+
+ {
+ :ok,
+ opts: Map.merge(context[:opts], %{
+ node: get_rabbit_hostname(),
+ timeout: 1000
+ })
+ }
+ end
+
+ test "validate: specifying both --minimal and --verbose is reported as invalid", context do
+ assert match?(
+ {:validation_failure, {:bad_argument, _}},
+ @command.validate([], Map.merge(context[:opts], %{minimal: true, verbose: true}))
+ )
+ end
+
+ test "validate: specifying multiple patterns is reported as an error", context do
+ assert @command.validate(["a", "b", "c"], context[:opts]) ==
+ {:validation_failure, :too_many_args}
+ end
+
+ test "validate_execution_environment: specifying a non-existent enabled_plugins_file is fine", context do
+ assert @command.validate_execution_environment(["a"], Map.merge(context[:opts], %{enabled_plugins_file: "none"})) == :ok
+ end
+
+ test "validate_execution_environment: specifying non existent plugins_dir is reported as an error", context do
+ assert @command.validate_execution_environment(["a"], Map.merge(context[:opts], %{plugins_dir: "none"})) ==
+ {:validation_failure, :plugins_dir_does_not_exist}
+ end
+
+ test "will report list of plugins from file for stopped node", context do
+ node = context[:opts][:node]
+ :ok = :rabbit_misc.rpc_call(node, :application, :stop, [:rabbitmq_stomp])
+ on_exit(fn ->
+ :rabbit_misc.rpc_call(node, :application, :start, [:rabbitmq_stomp])
+ end)
+ assert %{status: :node_down,
+ plugins: [%{name: :rabbitmq_federation, enabled: :enabled, running: false},
+ %{name: :rabbitmq_stomp, enabled: :enabled, running: false}]} =
+ @command.run([".*"], Map.merge(context[:opts], %{node: :nonode}))
+ end
+
+ test "will report list of started plugins for started node", context do
+ node = context[:opts][:node]
+ :ok = :rabbit_misc.rpc_call(node, :application, :stop, [:rabbitmq_stomp])
+ on_exit(fn ->
+ :rabbit_misc.rpc_call(node, :application, :start, [:rabbitmq_stomp])
+ end)
+ assert %{status: :running,
+ plugins: [%{name: :rabbitmq_federation, enabled: :enabled, running: true},
+ %{name: :rabbitmq_stomp, enabled: :enabled, running: false}]} =
+ @command.run([".*"], context[:opts])
+ end
+
+ test "will report description and dependencies for verbose mode", context do
+ assert %{status: :running,
+ plugins: [%{name: :rabbitmq_federation, enabled: :enabled, running: true, description: _, dependencies: [:amqp_client]},
+ %{name: :rabbitmq_stomp, enabled: :enabled, running: true, description: _, dependencies: [:amqp_client]}]} =
+ @command.run([".*"], Map.merge(context[:opts], %{verbose: true}))
+ end
+
+ test "will report plugin names in minimal mode", context do
+ assert %{status: :running,
+ plugins: [%{name: :rabbitmq_federation}, %{name: :rabbitmq_stomp}]} =
+ @command.run([".*"], Map.merge(context[:opts], %{minimal: true}))
+ end
+
+ test "by default lists all plugins", context do
+ set_enabled_plugins([:rabbitmq_federation], :online, context[:opts][:node], context[:opts])
+ on_exit(fn ->
+ set_enabled_plugins([:rabbitmq_stomp, :rabbitmq_federation], :online, context[:opts][:node], context[:opts])
+ end)
+ assert %{status: :running,
+ plugins: [%{name: :rabbitmq_federation, enabled: :enabled, running: true},
+ %{name: :rabbitmq_stomp, enabled: :not_enabled, running: false}]} =
+ @command.run([".*"], context[:opts])
+ end
+
+ test "with enabled flag lists only explicitly enabled plugins", context do
+ set_enabled_plugins([:rabbitmq_federation], :online, context[:opts][:node], context[:opts])
+ on_exit(fn ->
+ set_enabled_plugins([:rabbitmq_stomp, :rabbitmq_federation], :online, context[:opts][:node], context[:opts])
+ end)
+ assert %{status: :running,
+ plugins: [%{name: :rabbitmq_federation, enabled: :enabled, running: true}]} =
+ @command.run([".*"], Map.merge(context[:opts], %{enabled: true}))
+ end
+
+ test "with implicitly_enabled flag lists explicitly and implicitly enabled plugins", context do
+ set_enabled_plugins([:rabbitmq_federation], :online, context[:opts][:node], context[:opts])
+ on_exit(fn ->
+ set_enabled_plugins([:rabbitmq_stomp, :rabbitmq_federation], :online, context[:opts][:node], context[:opts])
+ end)
+ assert %{status: :running,
+ plugins: [%{name: :rabbitmq_federation, enabled: :enabled, running: true}]} =
+ @command.run([".*"], Map.merge(context[:opts], %{implicitly_enabled: true}))
+ end
+
+ test "will filter plugins by name with pattern provided", context do
+ set_enabled_plugins([:rabbitmq_federation], :online, context[:opts][:node], context[:opts])
+ on_exit(fn ->
+ set_enabled_plugins([:rabbitmq_stomp, :rabbitmq_federation], :online, context[:opts][:node], context[:opts])
+ end)
+ assert %{status: :running,
+ plugins: [%{name: :rabbitmq_federation}]} =
+ @command.run(["fede"], Map.merge(context[:opts], %{minimal: true}))
+ assert %{status: :running,
+ plugins: [%{name: :rabbitmq_stomp}]} =
+ @command.run(["stomp$"], Map.merge(context[:opts], %{minimal: true}))
+ end
+
+ test "validate: validation is OK when we use multiple plugins directories, one of them does not exist", context do
+ opts = get_opts_with_non_existing_plugins_directory(context)
+ assert @command.validate([], opts) == :ok
+ end
+
+ test "validate: validation is OK when we use multiple plugins directories, directories do exist", context do
+ opts = get_opts_with_existing_plugins_directory(context)
+ assert @command.validate([], opts) == :ok
+ end
+
+ test "should succeed when using multiple plugins directories, one of them does not exist", context do
+ opts = get_opts_with_non_existing_plugins_directory(context)
+ assert %{status: :running,
+ plugins: [%{name: :rabbitmq_federation}, %{name: :rabbitmq_stomp}]} =
+ @command.run([".*"], Map.merge(opts, %{minimal: true}))
+ end
+
+
+ test "should succeed when using multiple plugins directories, directories do exist and do contain plugins", context do
+ opts = get_opts_with_existing_plugins_directory(context)
+ assert %{status: :running,
+ plugins: [%{name: :rabbitmq_federation}, %{name: :rabbitmq_stomp}]} =
+ @command.run([".*"], Map.merge(opts, %{minimal: true}))
+ end
+
+ test "should list plugins when using multiple plugins directories", context do
+ plugins_directory = fixture_plugins_path("plugins-subdirectory-01")
+ opts = get_opts_with_plugins_directories(context, [plugins_directory])
+ switch_plugins_directories(context[:opts][:plugins_dir], opts[:plugins_dir])
+ reset_enabled_plugins_to_preconfigured_defaults(context)
+ assert %{status: :running,
+ plugins: [%{name: :mock_rabbitmq_plugins_01}, %{name: :mock_rabbitmq_plugins_02},
+ %{name: :rabbitmq_federation}, %{name: :rabbitmq_stomp}]} =
+ @command.run([".*"], Map.merge(opts, %{minimal: true}))
+ end
+
+ test "will report list of plugins with latest version picked", context do
+ plugins_directory_01 = fixture_plugins_path("plugins-subdirectory-01")
+ plugins_directory_02 = fixture_plugins_path("plugins-subdirectory-02")
+ opts = get_opts_with_plugins_directories(context, [plugins_directory_01, plugins_directory_02])
+ switch_plugins_directories(context[:opts][:plugins_dir], opts[:plugins_dir])
+ reset_enabled_plugins_to_preconfigured_defaults(context)
+ assert %{status: :running,
+ plugins: [%{name: :mock_rabbitmq_plugins_01, enabled: :not_enabled, running: false, version: '0.2.0'},
+ %{name: :mock_rabbitmq_plugins_02, enabled: :not_enabled, running: false, version: '0.2.0'},
+ %{name: :rabbitmq_federation, enabled: :enabled, running: true},
+ %{name: :rabbitmq_stomp, enabled: :enabled, running: true}]} =
+ @command.run([".*"], opts)
+ end
+
+ test "will report both running and pending upgrade versions", context do
+ plugins_directory_01 = fixture_plugins_path("plugins-subdirectory-01")
+ plugins_directory_02 = fixture_plugins_path("plugins-subdirectory-02")
+ opts = get_opts_with_plugins_directories(context, [plugins_directory_01])
+ switch_plugins_directories(context[:opts][:plugins_dir], opts[:plugins_dir])
+ set_enabled_plugins([:mock_rabbitmq_plugins_02, :rabbitmq_federation, :rabbitmq_stomp],
+ :online, get_rabbit_hostname(), opts)
+ assert %{status: :running,
+ plugins: [%{name: :mock_rabbitmq_plugins_01, enabled: :not_enabled, running: false, version: '0.2.0'},
+ %{name: :mock_rabbitmq_plugins_02, enabled: :enabled, running: true, version: '0.1.0', running_version: '0.1.0'},
+ %{name: :rabbitmq_federation, enabled: :enabled, running: true},
+ %{name: :rabbitmq_stomp, enabled: :enabled, running: true}]} =
+ @command.run([".*"], opts)
+ opts = get_opts_with_plugins_directories(context, [plugins_directory_01, plugins_directory_02])
+ switch_plugins_directories(context[:opts][:plugins_dir], opts[:plugins_dir])
+ assert %{status: :running,
+ plugins: [%{name: :mock_rabbitmq_plugins_01, enabled: :not_enabled, running: false, version: '0.2.0'},
+ %{name: :mock_rabbitmq_plugins_02, enabled: :enabled, running: true, version: '0.2.0', running_version: '0.1.0'},
+ %{name: :rabbitmq_federation, enabled: :enabled, running: true},
+ %{name: :rabbitmq_stomp, enabled: :enabled, running: true}]} =
+ @command.run([".*"], opts)
+ end
+end
diff --git a/deps/rabbitmq_cli/test/plugins/plugins_formatter_test.exs b/deps/rabbitmq_cli/test/plugins/plugins_formatter_test.exs
new file mode 100644
index 0000000000..9bf185d7e0
--- /dev/null
+++ b/deps/rabbitmq_cli/test/plugins/plugins_formatter_test.exs
@@ -0,0 +1,45 @@
+## This Source Code Form is subject to the terms of the Mozilla Public
+## License, v. 2.0. If a copy of the MPL was not distributed with this
+## file, You can obtain one at https://mozilla.org/MPL/2.0/.
+##
+## Copyright (c) 2007-2020 VMware, Inc. or its affiliates. All rights reserved.
+
+
+defmodule PluginsFormatterTest do
+ use ExUnit.Case, async: false
+
+ @formatter RabbitMQ.CLI.Formatters.Plugins
+
+ test "format_output with --silent and --minimal" do
+ result = @formatter.format_output(
+ %{status: :running,
+ plugins: [%{name: :amqp_client, enabled: :implicit, running: true, version: '3.7.0', running_version: nil},
+ %{name: :mock_rabbitmq_plugins_01, enabled: :not_enabled, running: false, version: '0.2.0', running_version: nil},
+ %{name: :mock_rabbitmq_plugins_02, enabled: :enabled, running: true, version: '0.2.0', running_version: '0.1.0'},
+ %{name: :rabbitmq_federation, enabled: :enabled, running: true, version: '3.7.0', running_version: nil},
+ %{name: :rabbitmq_stomp, enabled: :enabled, running: true, version: '3.7.0', running_version: nil}],
+ format: :minimal}, %{node: "rabbit@localhost", silent: true})
+ assert result == ["amqp_client",
+ "mock_rabbitmq_plugins_01",
+ "mock_rabbitmq_plugins_02",
+ "rabbitmq_federation",
+ "rabbitmq_stomp"]
+ end
+
+ test "format_output pending upgrade version message" do
+ result = @formatter.format_output(
+ %{status: :running,
+ plugins: [%{name: :amqp_client, enabled: :implicit, running: true, version: '3.7.0', running_version: nil},
+ %{name: :mock_rabbitmq_plugins_01, enabled: :not_enabled, running: false, version: '0.2.0', running_version: nil},
+ %{name: :mock_rabbitmq_plugins_02, enabled: :enabled, running: true, version: '0.2.0', running_version: '0.1.0'},
+ %{name: :rabbitmq_federation, enabled: :enabled, running: true, version: '3.7.0', running_version: nil},
+ %{name: :rabbitmq_stomp, enabled: :enabled, running: true, version: '3.7.0', running_version: nil}],
+ format: :normal}, %{node: "rabbit@localhost"})
+ assert result == [" Configured: E = explicitly enabled; e = implicitly enabled",
+ " | Status: * = running on rabbit@localhost", " |/",
+ "[e*] amqp_client 3.7.0", "[ ] mock_rabbitmq_plugins_01 0.2.0",
+ "[E*] mock_rabbitmq_plugins_02 0.1.0 (pending upgrade to 0.2.0)",
+ "[E*] rabbitmq_federation 3.7.0", "[E*] rabbitmq_stomp 3.7.0"]
+ end
+
+end
diff --git a/deps/rabbitmq_cli/test/plugins/set_plugins_command_test.exs b/deps/rabbitmq_cli/test/plugins/set_plugins_command_test.exs
new file mode 100644
index 0000000000..3ebc3dfc98
--- /dev/null
+++ b/deps/rabbitmq_cli/test/plugins/set_plugins_command_test.exs
@@ -0,0 +1,157 @@
+## This Source Code Form is subject to the terms of the Mozilla Public
+## License, v. 2.0. If a copy of the MPL was not distributed with this
+## file, You can obtain one at https://mozilla.org/MPL/2.0/.
+##
+## Copyright (c) 2007-2020 VMware, Inc. or its affiliates. All rights reserved.
+
+defmodule SetPluginsCommandTest do
+ use ExUnit.Case, async: false
+ import TestHelper
+
+ @command RabbitMQ.CLI.Plugins.Commands.SetCommand
+
+
+ setup_all do
+ RabbitMQ.CLI.Core.Distribution.start()
+ node = get_rabbit_hostname()
+
+ {:ok, plugins_file} = :rabbit_misc.rpc_call(node,
+ :application, :get_env,
+ [:rabbit, :enabled_plugins_file])
+ {:ok, plugins_dir} = :rabbit_misc.rpc_call(node,
+ :application, :get_env,
+ [:rabbit, :plugins_dir])
+ rabbitmq_home = :rabbit_misc.rpc_call(node, :code, :lib_dir, [:rabbit])
+
+ {:ok, [enabled_plugins]} = :file.consult(plugins_file)
+
+ opts = %{enabled_plugins_file: plugins_file,
+ plugins_dir: plugins_dir,
+ rabbitmq_home: rabbitmq_home,
+ online: false, offline: false}
+
+ on_exit(fn ->
+ set_enabled_plugins(enabled_plugins, :online, get_rabbit_hostname(),opts)
+ end)
+
+ {:ok, opts: opts}
+ end
+
+ setup context do
+
+ set_enabled_plugins([:rabbitmq_stomp, :rabbitmq_federation],
+ :online,
+ get_rabbit_hostname(),
+ context[:opts])
+
+ {
+ :ok,
+ opts: Map.merge(context[:opts], %{
+ node: get_rabbit_hostname(),
+ timeout: 1000
+ })
+ }
+ end
+
+ test "validate: specifying both --online and --offline is reported as invalid", context do
+ assert match?(
+ {:validation_failure, {:bad_argument, _}},
+ @command.validate([], Map.merge(context[:opts], %{online: true, offline: true}))
+ )
+ end
+
+ test "validate_execution_environment: specifying a non-existent enabled_plugins_file is fine", context do
+ assert @command.validate_execution_environment([], Map.merge(context[:opts], %{enabled_plugins_file: "none"})) ==
+ :ok
+ end
+
+ test "validate_execution_environment: specifying non existent plugins_dir is reported as an error", context do
+ assert @command.validate_execution_environment([], Map.merge(context[:opts], %{plugins_dir: "none"})) ==
+ {:validation_failure, :plugins_dir_does_not_exist}
+ end
+
+ test "will write enabled plugins file if node is inaccessible and report implicitly enabled list", context do
+ assert {:stream, test_stream} =
+ @command.run(["rabbitmq_stomp"], Map.merge(context[:opts], %{node: :nonode}))
+ assert [[:rabbitmq_stomp],
+ %{mode: :offline, set: [:rabbitmq_stomp]}] =
+ Enum.to_list(test_stream)
+ assert {:ok, [[:rabbitmq_stomp]]} = :file.consult(context[:opts][:enabled_plugins_file])
+ assert [:amqp_client, :rabbitmq_federation, :rabbitmq_stomp] =
+ Enum.sort(:rabbit_misc.rpc_call(context[:opts][:node], :rabbit_plugins, :active, []))
+ end
+
+ test "will write enabled plugins in offline mode and report implicitly enabled list", context do
+ assert {:stream, test_stream} =
+ @command.run(["rabbitmq_stomp"], Map.merge(context[:opts], %{offline: true, online: false}))
+ assert [[:rabbitmq_stomp],
+ %{mode: :offline, set: [:rabbitmq_stomp]}] =
+ Enum.to_list(test_stream)
+ assert {:ok, [[:rabbitmq_stomp]]} = :file.consult(context[:opts][:enabled_plugins_file])
+ assert [:amqp_client, :rabbitmq_federation, :rabbitmq_stomp] =
+ Enum.sort(:rabbit_misc.rpc_call(context[:opts][:node], :rabbit_plugins, :active, []))
+ end
+
+ test "will update list of plugins and start/stop enabled/disabled plugins", context do
+ assert {:stream, test_stream0} = @command.run(["rabbitmq_stomp"], context[:opts])
+ assert [[:rabbitmq_stomp],
+ %{mode: :online,
+ started: [], stopped: [:rabbitmq_federation],
+ set: [:rabbitmq_stomp]}] =
+ Enum.to_list(test_stream0)
+ assert {:ok, [[:rabbitmq_stomp]]} = :file.consult(context[:opts][:enabled_plugins_file])
+ assert [:amqp_client, :rabbitmq_stomp] =
+ Enum.sort(:rabbit_misc.rpc_call(context[:opts][:node], :rabbit_plugins, :active, []))
+ assert {:stream, test_stream1} = @command.run(["rabbitmq_federation"], context[:opts])
+ assert [[:rabbitmq_federation],
+ %{mode: :online,
+ started: [:rabbitmq_federation], stopped: [:rabbitmq_stomp],
+ set: [:rabbitmq_federation]}] =
+ Enum.to_list(test_stream1)
+ assert {:ok, [[:rabbitmq_federation]]} = :file.consult(context[:opts][:enabled_plugins_file])
+ assert [:amqp_client, :rabbitmq_federation] =
+ Enum.sort(:rabbit_misc.rpc_call(context[:opts][:node], :rabbit_plugins, :active, []))
+ end
+
+ test "can disable all plugins", context do
+ assert {:stream, test_stream} = @command.run([], context[:opts])
+ assert [[],
+ %{mode: :online,
+ started: [], stopped: [:rabbitmq_federation, :rabbitmq_stomp],
+ set: []}] =
+ Enum.to_list(test_stream)
+ assert {:ok, [[]]} = :file.consult(context[:opts][:enabled_plugins_file])
+ assert [] = Enum.sort(:rabbit_misc.rpc_call(context[:opts][:node], :rabbit_plugins, :active, []))
+ end
+
+ test "can set multiple plugins", context do
+ set_enabled_plugins([], :online, get_rabbit_hostname(), context[:opts])
+ assert {:stream, test_stream} =
+ @command.run(["rabbitmq_federation", "rabbitmq_stomp"], context[:opts])
+ assert [[:rabbitmq_federation, :rabbitmq_stomp],
+ %{mode: :online,
+ started: [:rabbitmq_federation, :rabbitmq_stomp],
+ stopped: [],
+ set: [:rabbitmq_federation, :rabbitmq_stomp]}] =
+ Enum.to_list(test_stream)
+ assert {:ok, [[:rabbitmq_federation, :rabbitmq_stomp]]} =
+ :file.consult(context[:opts][:enabled_plugins_file])
+ assert [:amqp_client, :rabbitmq_federation, :rabbitmq_stomp] =
+ Enum.sort(:rabbit_misc.rpc_call(context[:opts][:node], :rabbit_plugins, :active, []))
+ end
+
+ test "run: does not enable plugins with unmet version requirements", context do
+ set_enabled_plugins([], :online, context[:opts][:node], context[:opts])
+
+ plugins_directory = fixture_plugins_path("plugins_with_version_requirements")
+ opts = get_opts_with_plugins_directories(context, [plugins_directory])
+ switch_plugins_directories(context[:opts][:plugins_dir], opts[:plugins_dir])
+
+
+ {:stream, _} = @command.run(["mock_rabbitmq_plugin_for_3_8"], opts)
+ check_plugins_enabled([:mock_rabbitmq_plugin_for_3_8], context)
+
+ {:error, _version_error} = @command.run(["mock_rabbitmq_plugin_for_3_7"], opts)
+ check_plugins_enabled([:mock_rabbitmq_plugin_for_3_8], context)
+ end
+end