Skip to content

Commit

Permalink
rabbitmq-cli: Deleting a non-existing user or vhost is fine
Browse files Browse the repository at this point in the history
This patch adapts several testcases to this behavior change. The goal is
to avoid transactions where there is no need for one.
  • Loading branch information
dumbbell committed Nov 23, 2022
1 parent 51e4d27 commit 2c5d75e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 18 deletions.
12 changes: 5 additions & 7 deletions deps/rabbitmq_cli/test/ctl/clear_permissions_command_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,9 @@ defmodule ClearPermissionsTest do
assert @command.validate(["too", "many"], %{}) == {:validation_failure, :too_many_args}
end

@tag user: "fake_user"
test "run: can't clear permissions for non-existing user", context do
assert @command.run([context[:user]], context[:opts]) ==
{:error, {:no_such_user, context[:user]}}
@tag user: "fake_user", vhost: @default_vhost
test "run: clearing permissions for non-existing user still succeeds", context do
assert @command.run([context[:user]], context[:opts]) == :ok
end

@tag user: @user, vhost: @default_vhost
Expand All @@ -85,9 +84,8 @@ defmodule ClearPermissionsTest do
end

@tag user: @user, vhost: "bad_vhost"
test "run: on an invalid vhost, return no_such_vhost error", context do
assert @command.run([context[:user]], context[:opts]) ==
{:error, {:no_such_vhost, context[:vhost]}}
test "run: clearing permissions on a non-existent vhost still succeeds", context do
assert @command.run([context[:user]], context[:opts]) == :ok
end

@tag user: @user, vhost: @specific_vhost
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,14 @@ defmodule ClearTopicPermissionsTest do
{:validation_failure, :too_many_args}
end

@tag user: "fake_user"
test "run: can't clear topic permissions for non-existing user", context do
assert @command.run([context[:user]], context[:opts]) ==
{:error, {:no_such_user, context[:user]}}
@tag user: "fake_user", vhost: @specific_vhost
test "run: clearing topic permissions for non-existing user still succeeds", context do
assert @command.run([context[:user]], context[:opts]) == :ok
end

@tag user: @user, vhost: "bad_vhost"
test "run: on an invalid vhost, return no_such_vhost error", context do
assert @command.run([context[:user]], context[:opts]) ==
{:error, {:no_such_vhost, context[:vhost]}}
test "run: clearing topic permissions on an invalid vhost still succeeds", context do
assert @command.run([context[:user]], context[:opts]) == :ok
end

@tag user: @user, vhost: @specific_vhost
Expand Down
4 changes: 2 additions & 2 deletions deps/rabbitmq_cli/test/ctl/delete_user_command_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ defmodule DeleteUserCommandTest do
end

@tag user: @user
test "run: An invalid username returns an error", context do
assert @command.run(["no_one"], context[:opts]) == {:error, {:no_such_user, "no_one"}}
test "run: deleting a non-existing user still succeeds", context do
assert @command.run(["no_one"], context[:opts]) == :ok
end

@tag user: @user
Expand Down
4 changes: 2 additions & 2 deletions deps/rabbitmq_cli/test/rabbitmqctl_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ defmodule RabbitMQCtlTest do
end

test "a command that fails with an error exits with a reasonable error code" do
command = ["delete_user", "voldemort"]
capture_io(:stderr, fn -> error_check(command, exit_nouser()) end)
command = ["set_vhost_tags", "voldemort", "mytag"]
capture_io(:stderr, fn -> error_check(command, exit_dataerr()) end)
end

test "a mcommand with an unsupported option as the first command-line arg fails gracefully" do
Expand Down

0 comments on commit 2c5d75e

Please sign in to comment.