Refactor test helpers and add new counting tests to add, delete commands

This commit is contained in:
Brandon Shroyer 2016-03-18 11:33:51 +00:00
parent b87109e12f
commit 36c59f97a1
5 changed files with 22 additions and 6 deletions

View File

@ -53,6 +53,7 @@ defmodule AddUserCommandTest do
@tag user: "someone", password: "password"
test "default case completes successfully", context do
assert AddUserCommand.add_user([context[:user], context[:password]], context[:opts]) == :ok
assert list_users |> Enum.count(fn(record) -> record[:user] == context[:user] end) == 1
end
@tag user: "", password: "password"
@ -69,5 +70,6 @@ defmodule AddUserCommandTest do
test "adding an existing user returns an error", context do
TestHelper.add_user(context[:user], context[:password])
assert AddUserCommand.add_user([context[:user], context[:password]], context[:opts]) == {:error, {:user_already_exists, context[:user]}}
assert list_users |> Enum.count(fn(record) -> record[:user] == context[:user] end) == 1
end
end

View File

@ -49,11 +49,13 @@ defmodule AddVhostCommandTest do
@tag vhost: "test"
test "A valid name to an active RabbitMQ node is successful", context do
assert AddVhostCommand.add_vhost([context[:vhost]], context[:opts]) == :ok
assert list_vhosts |> Enum.count(fn(record) -> record[:name] == context[:vhost] end) == 1
end
@tag vhost: ""
test "An empty string to an active RabbitMQ node is still successful", context do
assert AddVhostCommand.add_vhost([context[:vhost]], context[:opts]) == :ok
assert list_vhosts |> Enum.count(fn(record) -> record[:name] == context[:vhost] end) == 1
end
test "A call to invalid or inactive RabbitMQ node returns a nodedown" do
@ -68,5 +70,6 @@ defmodule AddVhostCommandTest do
add_vhost context[:vhost]
assert AddVhostCommand.add_vhost([context[:vhost]], context[:opts]) ==
{:error, {:vhost_already_exists, context[:vhost]}}
assert list_vhosts |> Enum.count(fn(record) -> record[:name] == context[:vhost] end) == 1
end
end

View File

@ -49,6 +49,7 @@ defmodule DeleteUserCommandTest do
@tag user: "username"
test "A valid username returns ok", context do
assert DeleteUserCommand.delete_user([context[:user]], context[:opts]) == :ok
assert list_users |> Enum.count(fn(record) -> record[:user] == context[:user] end) == 0
end
test "An invalid Rabbit node returns a bad rpc message" do

View File

@ -51,11 +51,13 @@ defmodule DeleteVhostCommandTest do
@tag vhost: "test"
test "A valid name to an active RabbitMQ node is successful", context do
assert DeleteVhostCommand.delete_vhost([context[:vhost]], context[:opts]) == :ok
assert list_vhosts |> Enum.count(fn(record) -> record[:name] == context[:vhost] end) == 0
end
@tag vhost: ""
test "An empty string to an active RabbitMQ node is successful", context do
assert DeleteVhostCommand.delete_vhost([context[:vhost]], context[:opts]) == :ok
assert list_vhosts |> Enum.count(fn(record) -> record[:name] == context[:vhost] end) == 0
end
test "A call to invalid or inactive RabbitMQ node returns a nodedown" do

View File

@ -26,26 +26,34 @@ defmodule TestHelper do
end
def add_vhost(name) do
:rabbit_misc.rpc_call(get_rabbit_hostname, :rabbit_vhost, :add, [name])
:rpc.call(get_rabbit_hostname, :rabbit_vhost, :add, [name])
end
def delete_vhost(name) do
:rabbit_misc.rpc_call(get_rabbit_hostname, :rabbit_vhost, :delete, [name])
:rpc.call(get_rabbit_hostname, :rabbit_vhost, :delete, [name])
end
def list_vhosts() do
:rpc.call(get_rabbit_hostname, :rabbit_vhost, :info_all, [])
end
def add_user(name, password) do
:rabbit_misc.rpc_call(get_rabbit_hostname, :rabbit_auth_backend_internal, :add_user, [name, password])
:rpc.call(get_rabbit_hostname, :rabbit_auth_backend_internal, :add_user, [name, password])
end
def delete_user(name) do
:rabbit_misc.rpc_call(get_rabbit_hostname, :rabbit_auth_backend_internal, :delete_user, [name])
:rpc.call(get_rabbit_hostname, :rabbit_auth_backend_internal, :delete_user, [name])
end
def list_users() do
:rpc.call(get_rabbit_hostname, :rabbit_auth_backend_internal, :list_users, [])
end
def trace_on(vhost) do
:rabbit_misc.rpc_call(:rabbit_trace, :rabbit_trace, :start, [vhost])
:rpc.call(:rabbit_trace, :rabbit_trace, :start, [vhost])
end
def trace_off(vhost) do
:rabbit_misc.rpc_call(:rabbit_trace, :rabbit_trace, :stop, [vhost])
:rpc.call(:rabbit_trace, :rabbit_trace, :stop, [vhost])
end
end