Trait swanling::SwanlingDefaultType[][src]

pub trait SwanlingDefaultType<T> {
    fn set_default(
        self,
        key: SwanlingDefault,
        value: T
    ) -> Result<Box<Self>, SwanlingError>; }
Expand description

All run-time options can optionally be configured with custom defaults.

For example, you can optionally configure a default host for the load test. This is used if no per-SwanlingTaskSet host is defined, no --host CLI option is configured, and if the SwanlingTask itself doesn’t hard-code the host in the base url of its request. In that case, this host is added to all requests.

For example, a load test could be configured to default to running against a local development container, and the --host option could be used to override the host value to run the load test against the production environment.

Example

use swanling::prelude::*;

fn main() -> Result<(), SwanlingError> {
    SwanlingAttack::initialize()?
        .set_default(SwanlingDefault::Host, "local.dev")?;

    Ok(())
}

The following run-time options can be configured with a custom default using a borrowed string slice (&str):

The following run-time options can be configured with a custom default using a usize integer:

The following run-time flags can be configured with a custom default using a bool (and otherwise default to false).

The following run-time flags can be configured with a custom default using a SwanlingLogFormat.

Another Example

use swanling::prelude::*;

fn main() -> Result<(), SwanlingError> {
    SwanlingAttack::initialize()?
        // Do not reset the metrics after the load test finishes starting.
        .set_default(SwanlingDefault::NoResetMetrics, true)?
        // Display info level logs while the test runs.
        .set_default(SwanlingDefault::Verbose, 1)?
        // Log all requests made during the test to `./swanling-request.log`.
        .set_default(SwanlingDefault::RequestLog, "swanling-request.log")?;

    Ok(())
}

Required methods

Implementors