Flux AMQP v0.0.5 FluxAMQP.ConsumerTestUtils View Source

Simplify the creation of test cases for modules using FluxAMQP

Link to this section Summary

Functions

Add a log message which will be tested after the execution of the consumer.

Execute a test case which will assert the result and the log messages of FluxAMQP.Consumer.consume/3 implementation call made by the consumer module.

Set a function/0 which will be executed before the consumption assertion.

Set a map/0 that behaves as the meta data when one AMQP message is received.

Set a String.t/0 that behaves as the AMQP message received by the consumer.

Set the result expected to receive after a FluxAMQP.Consumer.consume/3 implementation call.

Link to this section Types

Link to this type

t()

View Source
t() :: %FluxAMQP.ConsumerTestUtils{
  consumer: module() | nil,
  do_before_function: term(),
  log_messages: [String.t()],
  meta: map(),
  payload: String.t(),
  result: any()
}

Link to this section Functions

Link to this function

add_log_message(utils, message)

View Source (since 0.0.4)
add_log_message(FluxAMQP.ConsumerTestUtils.t(), String.t()) :: Tunnel.t()

Add a log message which will be tested after the execution of the consumer.

Parameters

Examples

iex> import FluxAMQP.ConsumerTestUtils
...> utils =
...>   MyConsumer
...>   |> setup_consumer_test()
...>   |> add_log_message("MyConsumer received a message")
...> with %FluxAMQP.ConsumerTestUtils{} <- utils, do: :passed
:passed

Execute a test case which will assert the result and the log messages of FluxAMQP.Consumer.consume/3 implementation call made by the consumer module.

Parameters

Examples

iex> import FluxAMQP.ConsumerTestUtils
...> utils =
...>   FluxAMQP.ConsumerTestUtils.MyConsumer
...>   |> setup_consumer_test()
...>   |> set_meta(%{routing_key: "test.route"})
...>   |> set_payload(~s({"success": true}))
...>   |> do_before(fn _utils, _channel -> :ok end)
...>   |> set_result(:ok)
...>   |> add_log_message("MyConsumer received a message")
...>   |> consumer_test()
...> with %FluxAMQP.ConsumerTestUtils{} <- utils, do: :passed
:passed

Set a function/0 which will be executed before the consumption assertion.

Parameters

Examples

iex> import FluxAMQP.ConsumerTestUtils
...> utils =
...>   MyConsumer
...>   |> setup_consumer_test()
...>   |> set_meta(%{routing_key: "test"})
...> with %FluxAMQP.ConsumerTestUtils{} <- utils, do: :passed
:passed
Link to this function

set_meta(utils, meta)

View Source (since 0.0.4)
set_meta(FluxAMQP.ConsumerTestUtils.t(), map()) :: Test.Utils.t()

Set a map/0 that behaves as the meta data when one AMQP message is received.

Parameters

Examples

iex> import FluxAMQP.ConsumerTestUtils
...> utils =
...>   MyConsumer
...>   |> setup_consumer_test()
...>   |> set_meta(%{routing_key: "test"})
...> with %FluxAMQP.ConsumerTestUtils{} <- utils, do: :passed
:passed
Link to this function

set_payload(utils, payload)

View Source (since 0.0.4)

Set a String.t/0 that behaves as the AMQP message received by the consumer.

Parameters

Examples

iex> import FluxAMQP.ConsumerTestUtils
...> utils =
...>   MyConsumer
...>   |> setup_consumer_test()
...>   |> set_payload(~s({"hello": "world"}))
...> with %FluxAMQP.ConsumerTestUtils{} <- utils, do: :passed
:passed
Link to this function

set_result(utils, result)

View Source (since 0.0.4)

Create FluxAMQP.ConsumerTestUtils.t/0.

This is the starting function to a consumer pipe test case.

Parameters

Examples

iex> import FluxAMQP.ConsumerTestUtils
...> utils = setup_consumer_test(MyConsumer)
...> with %FluxAMQP.ConsumerTestUtils{} <- utils, do: :passed
:passed
Link to this function

setup_consumer_test(consumer)

View Source (since 0.0.4)
setup_consumer_test(module()) :: FluxAMQP.ConsumerTestUtils.t()

Set the result expected to receive after a FluxAMQP.Consumer.consume/3 implementation call.

Parameters

Examples

iex> import FluxAMQP.ConsumerTestUtils
...> utils =
...>   MyConsumer
...>   |> setup_consumer_test()
...>   |> set_result(:ok)
...> with %FluxAMQP.ConsumerTestUtils{} <- utils, do: :passed
:passed