Packages

Elixir messaging library using RabbitMQ, providing easy-to-use modules for message publishing, consuming, and retry handling

Current section

Files

Jump to
hare_mq lib publisher publisher_test.exs
Raw

lib/publisher/publisher_test.exs

defmodule HareMq.PublisherTest do
use HareMq.TestCase
alias HareMq.Connection
defmodule TestPublisher do
use HareMq.Publisher, exchange: "test_routing_key", routing_key: "test_routing_key"
end
setup do
Application.put_env(:hare_mq, :configuration, %{reconnect_interval_ms: 100})
stop_global(HareMq.Connection)
Connection.start_link([])
on_exit(fn -> stop_global(HareMq.Connection) end)
:ok
end
describe "start_link/1" do
test "starts the GenServer and connects to RabbitMQ" do
{:ok, pid} = TestPublisher.start_link()
# Verify the GenServer has a channel connected
assert {:ok, %AMQP.Channel{}} = TestPublisher.get_channel()
GenServer.stop(pid)
end
end
describe "publish_message/1" do
test "successfully publishes a binary message" do
message = "binary message"
{:ok, pid} = TestPublisher.start_link()
assert :ok = TestPublisher.publish_message(message)
GenServer.stop(pid)
end
test "successfully publishes a message as a map" do
message = %{key: "value"}
{:ok, pid} = TestPublisher.start_link()
assert :ok = TestPublisher.publish_message(message)
GenServer.stop(pid)
end
end
end