rodeo_tcp v0.2.0 Rodeo View Source

Rodeo provides a convenient way for creating a plain TCP mock server. This is useful for testing integrations with simple, proprietary TCP servers.

To use Rodeo, a listener has to be started before the test run and stopped afterwards.

Example

setup do
  {:ok, rodeo} = Rodeo.open(4040)

  on_exit(fn ->
    Rodeo.close(rodeo)
  end)

  {:ok, %{rodeo: rodeo}}
end

Link to this section Summary

Functions

Returns the call count of the given stub

Stops the listener for the given Rodeo instance

Starts a listener process and opens a new port on the local interface

Sends a message to the given Rodeo connection. It can be used within a stub in order to answer to a message, or independently, to initiate new communication

Creates a new stub for a specific incoming message

Link to this section Functions

Link to this function

call_count(arg, opts \\ []) View Source

Returns the call count of the given stub.

Example

stub = Rodeo.stub(rodeo, "Hey

")

{:ok, socket} = :gen_tcp.connect({127, 0, 0, 1}, 4040, active: false)
:ok = :gen_tcp.send(socket, "Hey

")

assert Rodeo.call_count(stub) == 1

Stops the listener for the given Rodeo instance.

Example

Rodeo.close(rodeo)

Starts a listener process and opens a new port on the local interface.

Example

{:ok, rodeo} = Rodeo.open(5050)

Sends a message to the given Rodeo connection. It can be used within a stub in order to answer to a message, or independently, to initiate new communication.

Example

Rodeo.stub(rodeo, "Hello\n", fn _ ->
  Rodeo.send(rodeo, "World\n")
end)

# or

Rodeo.send(rodeo, "Yeeehaaaa\n")
Link to this function

stub(rodeo, match, fun \\ nil) View Source

Creates a new stub for a specific incoming message.

Example

Rodeo.stub(rodeo, "Hello\n", fn _ ->
  # ...
end)