chaperon v0.3.1 Chaperon.Scenario View Source

Helper module to be used by scenario definition modules.

Imports Chaperon.Session and other helper modules for easy scenario definitions.

Example

defmodule MyScenario do
  use Chaperon.Scenario

  def init(session) do
    # Possibly do something with session before running scenario
    delay = :rand.uniform
    if delay > 0.5 do
      {:ok, session |> with_delay(delay |> seconds)}
    else
      {:ok, session}
    end
  end

  def run(session) do
    session
    |> post("/api/messages", json: %{message: "what's up?"})
    |> get("/api/messages")
  end

  def with_delay(session, delay) do
    put_in session.config[:delay], delay
  end
end

Link to this section Summary

Functions

Runs a given scenario module with a given config and returns the scenario's session annotated with histogram metrics via the Chaperon.Scenario.Metrics module. The returned Chaperon.Session will include histogram data for all performed Chaperon.Actionables, including for all run actions run asynchronously as part of the scenario.

Initializes a Chaperon.Scenario for a given session.

Returns the name of a Chaperon.Scenario based on the module its referring to.

Cleans up any resources after the Scenario was run (if needed). Can be overriden.

Link to this section Types

Link to this type

t()

View Source
t() :: %Chaperon.Scenario{module: module()}

Link to this section Functions

Link to this function

execute(scenario_mod, config)

View Source
execute(module(), map()) :: Chaperon.Session.t()

Runs a given scenario module with a given config and returns the scenario's session annotated with histogram metrics via the Chaperon.Scenario.Metrics module. The returned Chaperon.Session will include histogram data for all performed Chaperon.Actionables, including for all run actions run asynchronously as part of the scenario.

Link to this function

execute_nested(scenario, session, config)

View Source
Link to this function

init(scenario_mod, session)

View Source

Initializes a Chaperon.Scenario for a given session.

If scenario_mod defines an init/1 callback function, calls it with session and returns its return value.

Otherwise defaults to returning {:ok, session}.

Returns the name of a Chaperon.Scenario based on the module its referring to.

Example

iex> alias Chaperon.Scenario
iex> Scenario.name %Scenario{module: Scenarios.Bruteforce.Login}
"Scenarios.Bruteforce.Login"
Link to this function

nested_session(scenario, session, config)

View Source
Link to this function

new_session(scenario, config)

View Source
new_session(Chaperon.Scenario.t(), map()) :: Chaperon.Session.t()
Link to this function

run(scenario, session)

View Source
run(
  Chaperon.Scenario.t(),
  Chaperon.Session.t() | {:ok, Chaperon.Session.t()} | {:error, any()}
) :: Chaperon.Session.t() | {:error, any()}
Link to this function

session_name(scenario, arg2)

View Source
session_name(Chaperon.Scenario.t(), map()) :: String.t()

Cleans up any resources after the Scenario was run (if needed). Can be overriden.

If scenario's implementation module defines a teardown/1 callback function, calls it with session to clean up resources as needed.

Returns the given session afterwards.