Ditto
This commit is contained in:
parent
5476d25eab
commit
b0c80c3dac
|
|
@ -10,7 +10,10 @@ defmodule ListChannelsCommandTest do
|
|||
:net_kernel.start([:rabbitmqctl, :shortnames])
|
||||
:net_kernel.connect_node(get_rabbit_hostname)
|
||||
|
||||
close_all_connections()
|
||||
|
||||
on_exit([], fn ->
|
||||
close_all_connections()
|
||||
:erlang.disconnect_node(get_rabbit_hostname)
|
||||
:net_kernel.stop()
|
||||
end)
|
||||
|
|
@ -61,16 +64,12 @@ defmodule ListChannelsCommandTest do
|
|||
end)
|
||||
end
|
||||
|
||||
test "no channels by default", context do
|
||||
capture_io(fn ->
|
||||
assert [] == ListChannelsCommand.run([], context[:opts])
|
||||
end)
|
||||
end
|
||||
|
||||
test "default channel info keys are pid, user, consumer_count, and messages_unacknowledged", context do
|
||||
close_all_connections()
|
||||
capture_io(fn ->
|
||||
with_channel("/", fn(_channel) ->
|
||||
[chan] = ListChannelsCommand.run([], context[:opts])
|
||||
channels = ListChannelsCommand.run([], context[:opts])
|
||||
chan = Enum.at(channels, 0)
|
||||
assert Keyword.keys(chan) == ~w(pid user consumer_count messages_unacknowledged)a
|
||||
assert [user: "guest", consumer_count: 0, messages_unacknowledged: 0] == Keyword.delete(chan, :pid)
|
||||
end)
|
||||
|
|
@ -78,42 +77,47 @@ defmodule ListChannelsCommandTest do
|
|||
end
|
||||
|
||||
test "multiple channels on multiple connections", context do
|
||||
close_all_connections()
|
||||
capture_io(fn ->
|
||||
with_channel("/", fn(_channel1) ->
|
||||
with_channel("/", fn(_channel2) ->
|
||||
[chan1, chan2] = ListChannelsCommand.run(["pid", "user", "connection"], context[:opts])
|
||||
channels = ListChannelsCommand.run(["pid", "user", "connection"], context[:opts])
|
||||
chan1 = Enum.at(channels, 0)
|
||||
chan2 = Enum.at(channels, 1)
|
||||
assert Keyword.keys(chan1) == ~w(pid user connection)a
|
||||
assert Keyword.keys(chan2) == ~w(pid user connection)a
|
||||
assert "guest" == chan1[:user]
|
||||
assert "guest" == chan2[:user]
|
||||
assert chan1[:pid] !== chan2[:pid]
|
||||
assert chan1[:connection] !== chan2[:connection]
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
end
|
||||
|
||||
test "multiple channels on single connection", context do
|
||||
close_all_connections()
|
||||
capture_io(fn ->
|
||||
with_connection("/", fn(conn) ->
|
||||
{:ok, _} = AMQP.Channel.open(conn)
|
||||
{:ok, _} = AMQP.Channel.open(conn)
|
||||
|
||||
[chan1, chan2] = ListChannelsCommand.run(["pid", "user", "connection"], context[:opts])
|
||||
channels = ListChannelsCommand.run(["pid", "user", "connection"], context[:opts])
|
||||
chan1 = Enum.at(channels, 0)
|
||||
chan2 = Enum.at(channels, 1)
|
||||
assert Keyword.keys(chan1) == ~w(pid user connection)a
|
||||
assert Keyword.keys(chan2) == ~w(pid user connection)a
|
||||
assert "guest" == chan1[:user]
|
||||
assert "guest" == chan2[:user]
|
||||
assert chan1[:pid] !== chan2[:pid]
|
||||
assert chan1[:connection] == chan2[:connection]
|
||||
end)
|
||||
end)
|
||||
end
|
||||
|
||||
test "info keys order is preserved", context do
|
||||
close_all_connections()
|
||||
capture_io(fn ->
|
||||
with_channel("/", fn(_channel) ->
|
||||
[chan] = ListChannelsCommand.run(~w(connection vhost name pid number user), context[:opts])
|
||||
channels = ListChannelsCommand.run(~w(connection vhost name pid number user), context[:opts])
|
||||
chan = Enum.at(channels, 0)
|
||||
assert Keyword.keys(chan) == ~w(connection vhost name pid number user)a
|
||||
end)
|
||||
end)
|
||||
|
|
|
|||
Loading…
Reference in New Issue