fake_server v0.5.0 FakeServer.Status

Provides an interface to create and destroy status.

The status must have:

  • a name
  • some config. Currently response_code and response_body are mandatory parameters on the config.

Summary

Functions

This function creates a new status

This function destroys all Status. Since status are reusable entities, there makes no sense to destroy only one of them. You should use this function when you want to perform a cleanup

Functions

create(name, map)

This function creates a new status.

Parameters

  • name: The name must be an atom. This name identifies the status on FakeServer.run/2 or FakeServer.run/3.
  • status: The atributes of the status. This represents the response of the fake server when a request arrives. Currently, the following options are accepted:
  • response_code: This parameter is mandatory. This is the code the fake server will respond with. Must be a valid http response code, like 200, 400 or 500.
  • response_body: This parameter is mandatory. This is the body of the response of the fake server. Can be any valid http body, like a plain text or a JSON.

Return values

If everything is ok, this function will return :ok. Otherwise, it will return an error and the reason.

Examples

FakeServer.Status.create(:status200,
                         %{response_code: 200, response_body: ~s<"username": "mr_user">})
:ok
FakeServer.Status.create(:status500,
                         %{response_code: 500, response_body: ~s<"error": "internal server error">})
:ok
FakeServer.Status.create(:status403,
                         %{response_code: 403, response_body: ~s<"error": "forbidden">})
:ok
FakeServer.Status.create(:status200,
                         %{response_code: 200, response_body: ~s<"username": "mr_user">, response_headers: %{"Content-Length": 5}})
:ok
destroy_all()

This function destroys all Status. Since status are reusable entities, there makes no sense to destroy only one of them. You should use this function when you want to perform a cleanup.

Examples

FakeServer.Status.destroy_all
:ok

If there are no status, this function will return an error:

FakeServer.Status.destroy_all
{:error, :no_status_to_destroy}