This repository has been archived by the owner on Sep 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexchange_declare_test.exs
65 lines (54 loc) · 2.3 KB
/
exchange_declare_test.exs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
defmodule RabbitHole.Protocol.ExchangeDeclareTest do
use ExUnit.Case
alias RabbitHole.Protocol.{Connection, Channel, Exchange}
@exchange "my_exchange"
describe "channel and connection kept open" do
setup do
{:ok, conn} = Connection.open()
{:ok, chan} = Channel.open(conn)
:ok = Exchange.delete(chan, @exchange)
on_exit(fn ->
:ok = Channel.close(chan)
:ok = Connection.close(conn)
end)
[conn: conn, chan: chan]
end
test "declares an exchange", params do
assert exchange = Exchange.declare(params.chan, @exchange)
# redeclaration of the same exchange checks its name and all its params
assert ^exchange = Exchange.declare(params.chan, @exchange)
end
test "checks existence of an exchange", params do
assert exchange = Exchange.declare(params.chan, @exchange)
# redeclaration of a exchange with :passive checks if a exchange with the same name exits
assert ^exchange = Exchange.declare(params.chan, @exchange, :direct, [:passive])
end
end
describe "channel and connection closed as a result of an error" do
setup do
{:ok, conn} = Connection.open()
{:ok, chan} = Channel.open(conn)
:ok = Exchange.delete(chan, @exchange)
[conn: conn, chan: chan]
end
test "fails if a exchange with the given name doesn't exists", params do
# NOT_FOUND error
assert {{:shutdown, {:server_initiated_close, 404, _}}, _} =
catch_exit(Exchange.declare(params.chan, @exchange, :direct, [:passive]))
end
test "fails if a exchange with different type already exists", params do
# by default the exchange if of type :direct
assert exchange = Exchange.declare(params.chan, @exchange)
# PRECONDITION_FAILED error
assert {{:shutdown, {:server_initiated_close, 406, _}}, _} =
catch_exit(Exchange.declare(params.chan, @exchange, :fanout))
end
test "fails if a exchange with different params already exists", params do
# by default the exchange is not durable
assert exchange = Exchange.declare(params.chan, @exchange)
# PRECONDITION_FAILED error
assert {{:shutdown, {:server_initiated_close, 406, _}}, _} =
catch_exit(Exchange.declare(params.chan, @exchange, :direct, [:durable]))
end
end
end