Refactor test helpers and add new counting tests to add, delete commands
This commit is contained in:
parent
b87109e12f
commit
36c59f97a1
|
|
@ -53,6 +53,7 @@ defmodule AddUserCommandTest do
|
||||||
@tag user: "someone", password: "password"
|
@tag user: "someone", password: "password"
|
||||||
test "default case completes successfully", context do
|
test "default case completes successfully", context do
|
||||||
assert AddUserCommand.add_user([context[:user], context[:password]], context[:opts]) == :ok
|
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
|
end
|
||||||
|
|
||||||
@tag user: "", password: "password"
|
@tag user: "", password: "password"
|
||||||
|
|
@ -69,5 +70,6 @@ defmodule AddUserCommandTest do
|
||||||
test "adding an existing user returns an error", context do
|
test "adding an existing user returns an error", context do
|
||||||
TestHelper.add_user(context[:user], context[:password])
|
TestHelper.add_user(context[:user], context[:password])
|
||||||
assert AddUserCommand.add_user([context[:user], context[:password]], context[:opts]) == {:error, {:user_already_exists, context[:user]}}
|
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
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -49,11 +49,13 @@ defmodule AddVhostCommandTest do
|
||||||
@tag vhost: "test"
|
@tag vhost: "test"
|
||||||
test "A valid name to an active RabbitMQ node is successful", context do
|
test "A valid name to an active RabbitMQ node is successful", context do
|
||||||
assert AddVhostCommand.add_vhost([context[:vhost]], context[:opts]) == :ok
|
assert AddVhostCommand.add_vhost([context[:vhost]], context[:opts]) == :ok
|
||||||
|
assert list_vhosts |> Enum.count(fn(record) -> record[:name] == context[:vhost] end) == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
@tag vhost: ""
|
@tag vhost: ""
|
||||||
test "An empty string to an active RabbitMQ node is still successful", context do
|
test "An empty string to an active RabbitMQ node is still successful", context do
|
||||||
assert AddVhostCommand.add_vhost([context[:vhost]], context[:opts]) == :ok
|
assert AddVhostCommand.add_vhost([context[:vhost]], context[:opts]) == :ok
|
||||||
|
assert list_vhosts |> Enum.count(fn(record) -> record[:name] == context[:vhost] end) == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
test "A call to invalid or inactive RabbitMQ node returns a nodedown" do
|
test "A call to invalid or inactive RabbitMQ node returns a nodedown" do
|
||||||
|
|
@ -68,5 +70,6 @@ defmodule AddVhostCommandTest do
|
||||||
add_vhost context[:vhost]
|
add_vhost context[:vhost]
|
||||||
assert AddVhostCommand.add_vhost([context[:vhost]], context[:opts]) ==
|
assert AddVhostCommand.add_vhost([context[:vhost]], context[:opts]) ==
|
||||||
{:error, {:vhost_already_exists, context[:vhost]}}
|
{:error, {:vhost_already_exists, context[:vhost]}}
|
||||||
|
assert list_vhosts |> Enum.count(fn(record) -> record[:name] == context[:vhost] end) == 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,7 @@ defmodule DeleteUserCommandTest do
|
||||||
@tag user: "username"
|
@tag user: "username"
|
||||||
test "A valid username returns ok", context do
|
test "A valid username returns ok", context do
|
||||||
assert DeleteUserCommand.delete_user([context[:user]], context[:opts]) == :ok
|
assert DeleteUserCommand.delete_user([context[:user]], context[:opts]) == :ok
|
||||||
|
assert list_users |> Enum.count(fn(record) -> record[:user] == context[:user] end) == 0
|
||||||
end
|
end
|
||||||
|
|
||||||
test "An invalid Rabbit node returns a bad rpc message" do
|
test "An invalid Rabbit node returns a bad rpc message" do
|
||||||
|
|
|
||||||
|
|
@ -51,11 +51,13 @@ defmodule DeleteVhostCommandTest do
|
||||||
@tag vhost: "test"
|
@tag vhost: "test"
|
||||||
test "A valid name to an active RabbitMQ node is successful", context do
|
test "A valid name to an active RabbitMQ node is successful", context do
|
||||||
assert DeleteVhostCommand.delete_vhost([context[:vhost]], context[:opts]) == :ok
|
assert DeleteVhostCommand.delete_vhost([context[:vhost]], context[:opts]) == :ok
|
||||||
|
assert list_vhosts |> Enum.count(fn(record) -> record[:name] == context[:vhost] end) == 0
|
||||||
end
|
end
|
||||||
|
|
||||||
@tag vhost: ""
|
@tag vhost: ""
|
||||||
test "An empty string to an active RabbitMQ node is successful", context do
|
test "An empty string to an active RabbitMQ node is successful", context do
|
||||||
assert DeleteVhostCommand.delete_vhost([context[:vhost]], context[:opts]) == :ok
|
assert DeleteVhostCommand.delete_vhost([context[:vhost]], context[:opts]) == :ok
|
||||||
|
assert list_vhosts |> Enum.count(fn(record) -> record[:name] == context[:vhost] end) == 0
|
||||||
end
|
end
|
||||||
|
|
||||||
test "A call to invalid or inactive RabbitMQ node returns a nodedown" do
|
test "A call to invalid or inactive RabbitMQ node returns a nodedown" do
|
||||||
|
|
|
||||||
|
|
@ -26,26 +26,34 @@ defmodule TestHelper do
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_vhost(name) do
|
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
|
end
|
||||||
|
|
||||||
def delete_vhost(name) do
|
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
|
end
|
||||||
|
|
||||||
|
def list_vhosts() do
|
||||||
|
:rpc.call(get_rabbit_hostname, :rabbit_vhost, :info_all, [])
|
||||||
|
end
|
||||||
|
|
||||||
def add_user(name, password) do
|
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
|
end
|
||||||
|
|
||||||
def delete_user(name) do
|
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
|
end
|
||||||
|
|
||||||
|
def list_users() do
|
||||||
|
:rpc.call(get_rabbit_hostname, :rabbit_auth_backend_internal, :list_users, [])
|
||||||
|
end
|
||||||
|
|
||||||
def trace_on(vhost) do
|
def trace_on(vhost) do
|
||||||
:rabbit_misc.rpc_call(:rabbit_trace, :rabbit_trace, :start, [vhost])
|
:rpc.call(:rabbit_trace, :rabbit_trace, :start, [vhost])
|
||||||
end
|
end
|
||||||
|
|
||||||
def trace_off(vhost) do
|
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
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue