From 112ff3f3f50b8baa35d7690c28b2950514b20bcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20P=C3=A9dron?= Date: Tue, 12 Nov 2024 16:44:01 +0100 Subject: [PATCH] rabbitmq_cli: Prepare tests to run against a node with Khepri enabled by default --- .../change_cluster_node_type_command_test.exs | 2 +- .../test/ctl/force_boot_command_test.exs | 23 ++++++++++++------- .../test/ctl/force_reset_command_test.exs | 10 +++++++- .../test/ctl/reset_command_test.exs | 10 +++++++- .../diagnostics/schema_info_command_test.exs | 19 ++++++++++----- 5 files changed, 47 insertions(+), 17 deletions(-) diff --git a/deps/rabbitmq_cli/test/ctl/change_cluster_node_type_command_test.exs b/deps/rabbitmq_cli/test/ctl/change_cluster_node_type_command_test.exs index 20b8cc17a2d8..9b32a25871b3 100644 --- a/deps/rabbitmq_cli/test/ctl/change_cluster_node_type_command_test.exs +++ b/deps/rabbitmq_cli/test/ctl/change_cluster_node_type_command_test.exs @@ -64,7 +64,7 @@ defmodule ChangeClusterNodeTypeCommandTest do case :rabbit_misc.rpc_call(node, :rabbit_khepri, :is_enabled, []) do true -> assert match?( - :ok, + {:error, _}, @command.run(["ram"], context[:opts]) ) diff --git a/deps/rabbitmq_cli/test/ctl/force_boot_command_test.exs b/deps/rabbitmq_cli/test/ctl/force_boot_command_test.exs index aa5377102590..5ac152323d13 100644 --- a/deps/rabbitmq_cli/test/ctl/force_boot_command_test.exs +++ b/deps/rabbitmq_cli/test/ctl/force_boot_command_test.exs @@ -37,14 +37,21 @@ defmodule ForceBootCommandTest do end test "run: sets a force boot marker file on target node", context do - stop_rabbitmq_app() - on_exit(fn -> start_rabbitmq_app() end) - assert @command.run([], context[:opts]) == :ok - data_dir = :rpc.call(get_rabbit_hostname(), :rabbit, :data_dir, []) - - path = Path.join(data_dir, "force_load") - assert File.exists?(path) - File.rm(path) + node = get_rabbit_hostname() + case :rabbit_misc.rpc_call(node, :rabbit_khepri, :is_enabled, []) do + true -> + :ok + + false -> + stop_rabbitmq_app() + on_exit(fn -> start_rabbitmq_app() end) + assert @command.run([], context[:opts]) == :ok + data_dir = :rpc.call(node, :rabbit, :data_dir, []) + + path = Path.join(data_dir, "force_load") + assert File.exists?(path) + File.rm(path) + end end test "run: if RABBITMQ_MNESIA_DIR is defined, creates a force boot marker file" do diff --git a/deps/rabbitmq_cli/test/ctl/force_reset_command_test.exs b/deps/rabbitmq_cli/test/ctl/force_reset_command_test.exs index 481e42583520..0285a70abb0c 100644 --- a/deps/rabbitmq_cli/test/ctl/force_reset_command_test.exs +++ b/deps/rabbitmq_cli/test/ctl/force_reset_command_test.exs @@ -44,7 +44,15 @@ defmodule ForceResetCommandTest do test "run: reset request to an active node with a running rabbit app fails", context do add_vhost("some_vhost") assert vhost_exists?("some_vhost") - assert match?({:error, :mnesia_unexpectedly_running}, @command.run([], context[:opts])) + node = get_rabbit_hostname() + ret = @command.run([], context[:opts]) + case :rabbit_misc.rpc_call(node, :rabbit_khepri, :is_enabled, []) do + true -> + assert match?({:error, :rabbitmq_unexpectedly_running}, ret) + + false -> + assert match?({:error, :mnesia_unexpectedly_running}, ret) + end assert vhost_exists?("some_vhost") end diff --git a/deps/rabbitmq_cli/test/ctl/reset_command_test.exs b/deps/rabbitmq_cli/test/ctl/reset_command_test.exs index e8935ae7f414..85452b4cb841 100644 --- a/deps/rabbitmq_cli/test/ctl/reset_command_test.exs +++ b/deps/rabbitmq_cli/test/ctl/reset_command_test.exs @@ -44,7 +44,15 @@ defmodule ResetCommandTest do test "run: reset request to an active node with a running rabbit app fails", context do add_vhost("some_vhost") assert vhost_exists?("some_vhost") - assert match?({:error, :mnesia_unexpectedly_running}, @command.run([], context[:opts])) + node = get_rabbit_hostname() + ret = @command.run([], context[:opts]) + case :rabbit_misc.rpc_call(node, :rabbit_khepri, :is_enabled, []) do + true -> + assert match?({:error, :rabbitmq_unexpectedly_running}, ret) + + false -> + assert match?({:error, :mnesia_unexpectedly_running}, ret) + end assert vhost_exists?("some_vhost") end diff --git a/deps/rabbitmq_cli/test/diagnostics/schema_info_command_test.exs b/deps/rabbitmq_cli/test/diagnostics/schema_info_command_test.exs index fe58935421c8..2178bf6f9dfd 100644 --- a/deps/rabbitmq_cli/test/diagnostics/schema_info_command_test.exs +++ b/deps/rabbitmq_cli/test/diagnostics/schema_info_command_test.exs @@ -63,12 +63,19 @@ defmodule SchemaInfoCommandTest do end test "run: can filter info keys", context do - wanted_keys = ~w(name access_mode) - - assert match?( - [[name: _, access_mode: _] | _], - run_command_to_list(@command, [wanted_keys, context[:opts]]) - ) + node = context[:opts][:node] + case :rabbit_misc.rpc_call(node, :rabbit_khepri, :is_enabled, []) do + true -> + :ok + + false -> + wanted_keys = ~w(name access_mode) + + assert match?( + [[name: _, access_mode: _] | _], + run_command_to_list(@command, [wanted_keys, context[:opts]]) + ) + end end test "banner" do