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 section Functions
execute(scenario_mod, config)
View Sourceexecute(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.
execute_nested(scenario, session, config)
View Sourceexecute_nested(Chaperon.Scenario.t(), Chaperon.Session.t(), map()) :: Chaperon.Session.t()
init(scenario_mod, session)
View Sourceinit(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}.
initial_delay(session)
View Sourceinitial_delay(Chaperon.Session.t()) :: Chaperon.Session.t()
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"
nested_session(scenario, session, config)
View Sourcenested_session(Chaperon.Scenario.t(), Chaperon.Session.t(), map()) :: Chaperon.Session.t()
new_session(scenario, config)
View Sourcenew_session(Chaperon.Scenario.t(), map()) :: Chaperon.Session.t()
run(scenario, session)
View Sourcerun( Chaperon.Scenario.t(), Chaperon.Session.t() | {:ok, Chaperon.Session.t()} | {:error, any()} ) :: Chaperon.Session.t() | {:error, any()}
session_name(scenario, arg2)
View Sourcesession_name(Chaperon.Scenario.t(), map()) :: String.t()
teardown(scenario, session)
View Sourceteardown(Chaperon.Scenario.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.