Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
whatyouhide committed Nov 13, 2024
1 parent 693f629 commit 4428405
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 32 deletions.
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3'

services:
rabbitmq:
image: "rabbitmq:3.11.9-alpine"
Expand Down
27 changes: 15 additions & 12 deletions test/broadway_rabbitmq/ampq_client_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,15 @@ defmodule BroadwayRabbitMQ.AmqpClientTest do

test ":queue is required" do
assert AmqpClient.init([]) ==
{:error, "required option :queue not found, received options: []"}
{:error, "required :queue option not found, received options: []"}

assert AmqpClient.init(queue: nil) ==
{:error, "expected :queue to be a string, got: nil"}
{:error, "invalid value for :queue option: expected string, got: nil"}
end

test ":queue should be a string" do
assert AmqpClient.init(queue: :an_atom) ==
{:error, "expected :queue to be a string, got: :an_atom"}
{:error, "invalid value for :queue option: expected string, got: :an_atom"}

{:ok, config} = AmqpClient.init(queue: "my_queue")
assert config.queue == "my_queue"
Expand All @@ -165,9 +165,10 @@ defmodule BroadwayRabbitMQ.AmqpClientTest do
{:ok, opts} = AmqpClient.init(queue: "queue", metadata: [:routing_key, :headers])
assert opts[:metadata] == [:routing_key, :headers]

message =
~s(list element at position 0 in :metadata failed validation: expected "list element" ) <>
~s(to be an atom, got: "routing_key")
message = """
invalid list in :metadata option: invalid value for list element at position 0: expected \
atom, got: "routing_key"\
"""

assert AmqpClient.init(queue: "queue", metadata: ["routing_key", :headers]) ==
{:error, message}
Expand All @@ -177,18 +178,20 @@ defmodule BroadwayRabbitMQ.AmqpClientTest do
{:ok, opts} = AmqpClient.init(queue: "queue", bindings: [{"my-exchange", [arguments: []]}])
assert opts[:bindings] == [{"my-exchange", [arguments: []]}]

message =
~s(list element at position 0 in :bindings failed validation: expected binding to be ) <>
~s(a {exchange, opts} tuple, got: :something)
message = """
invalid list in :bindings option: invalid value for list element at position 0: \
expected binding to be a {exchange, opts} tuple, got: :something\
"""

assert AmqpClient.init(queue: "queue", bindings: [:something, :else]) ==
{:error, message}
end

test ":bindings with invalid binding options" do
message =
"list element at position 0 in :bindings failed validation: unknown options " <>
"[:invalid], valid options are: [:routing_key, :arguments]"
message = """
invalid list in :bindings option: invalid value for list element at position 0: \
unknown options [:invalid], valid options are: [:routing_key, :arguments]\
"""

assert AmqpClient.init(queue: "queue", bindings: [{"my-exchange", [invalid: true]}]) ==
{:error, message}
Expand Down
30 changes: 12 additions & 18 deletions test/broadway_rabbitmq/producer_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -230,27 +230,21 @@ defmodule BroadwayRabbitMQ.ProducerTest do
end

test "raise an ArgumentError with proper message when client options are invalid" do
assert_raise(
ArgumentError,
"invalid options given to BroadwayRabbitMQ.AmqpClient.init/1, expected :queue to be a string, got: nil",
fn ->
BroadwayRabbitMQ.Producer.init(queue: nil, on_failure: :reject_and_requeue)
end
)
message = ~r/invalid value for :queue option: expected string, got: nil/

assert_raise ArgumentError, message, fn ->
BroadwayRabbitMQ.Producer.init(queue: nil, on_failure: :reject_and_requeue)
end
end

test "raise an ArgumentError with proper message when backoff options are invalid" do
assert_raise(
ArgumentError,
~r/expected :backoff_type to be one of/,
fn ->
BroadwayRabbitMQ.Producer.init(
queue: "test",
backoff_type: :unknown_type,
on_failure: :reject_and_requeue
)
end
)
assert_raise ArgumentError, ~r/invalid value for :backoff_type/, fn ->
BroadwayRabbitMQ.Producer.init(
queue: "test",
backoff_type: :unknown_type,
on_failure: :reject_and_requeue
)
end
end

test "prints a deprecation warning when :on_failure is not specified" do
Expand Down

0 comments on commit 4428405

Please sign in to comment.