View Source Chaperon.Scenario (chaperon v0.3.1)

Helper module to be used by scenario definition modules.

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

example

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

@type t() :: %Chaperon.Scenario{module: module()}

Link to this section Functions

Link to this function

execute(scenario_mod, config)

View Source
@spec 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
@spec execute_nested(t(), Chaperon.Session.t(), map()) :: Chaperon.Session.t()
Link to this function

init(scenario_mod, session)

View Source
@spec init(module(), Chaperon.Session.t()) :: {:ok, Chaperon.Session.t()}

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}.

@spec initial_delay(Chaperon.Session.t()) :: Chaperon.Session.t()
@spec name(t()) :: String.t()

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

example

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
@spec nested_session(t(), Chaperon.Session.t(), map()) :: Chaperon.Session.t()
Link to this function

new_session(scenario, config)

View Source
@spec new_session(t(), map()) :: Chaperon.Session.t()
@spec run(
  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
@spec session_name(t(), map()) :: String.t()
Link to this function

teardown(scenario, session)

View Source
@spec teardown(t(), Chaperon.Session.t()) :: Chaperon.Session.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.