pub struct PrepareContainerContext<'a> { /* private fields */ }
Expand description

Context for preparing a container.

Created by TestContext::prepare_container and is used to configure the container before running it.

Implementations

Exposes a given port of the container to the host machine.

The given port is mapped to a random port on the host machine. Use ContainerContext::address_for_port to obtain the local port for a mapped port.

Inserts or updates an environment variable mapping for the container.

Example
use libcnb_test::{TestConfig, TestRunner};

TestRunner::default().run_test(
    TestConfig::new("heroku/builder:22", "test-fixtures/app"),
    |context| {
        context
            .prepare_container()
            .env("FOO", "FOO_VALUE")
            .env("BAR", "BAR_VALUE")
            .start_with_default_process(|container| {
                // ...
            });
    },
);

Adds or updates multiple environment variable mappings for the container.

Example
use libcnb_test::{TestConfig, TestRunner};

TestRunner::default().run_test(
    TestConfig::new("heroku/builder:22", "test-fixtures/app"),
    |context| {
        context
            .prepare_container()
            .envs(vec![("FOO", "FOO_VALUE"), ("BAR", "BAR_VALUE")])
            .start_with_default_process(|container| {
                // ...
            });
    },
);

Creates and starts the container configured by this context using the image’s default CNB process.

See: CNB App Developer Guide: Run a multi-process app - Default process type

Example
use libcnb_test::{TestConfig, TestRunner};

TestRunner::default().run_test(
    TestConfig::new("heroku/builder:22", "test-fixtures/app"),
    |context| {
        context
            .prepare_container()
            .start_with_default_process(|container| {
                // ...
            });
    },
);

Creates and starts the container configured by this context using the image’s default CNB process and given arguments.

See: CNB App Developer Guide: Run a multi-process app - Default process type with additional arguments

Example
use libcnb_test::{TestConfig, TestRunner};

TestRunner::default().run_test(
    TestConfig::new("heroku/builder:22", "test-fixtures/app"),
    |context| {
        context.prepare_container().start_with_default_process_args(
            ["--version"],
            |container| {
                // ...
            },
        );
    },
);

Creates and starts the container configured by this context using the given CNB process.

See: CNB App Developer Guide: Run a multi-process app - Non-default process-type

Example
use libcnb_test::{TestConfig, TestRunner};

TestRunner::default().run_test(
    TestConfig::new("heroku/builder:22", "test-fixtures/app"),
    |context| {
        context
            .prepare_container()
            .start_with_process("worker", |container| {
                // ...
            });
    },
);

Creates and starts the container configured by this context using the given CNB process and arguments.

See: CNB App Developer Guide: Run a multi-process app - Non-default process-type with additional arguments

Example
use libcnb_test::{TestConfig, TestRunner};

TestRunner::default().run_test(
    TestConfig::new("heroku/builder:22", "test-fixtures/app"),
    |context| {
        context.prepare_container().start_with_process_args(
            "worker",
            ["--config", "foo.toml"],
            |container| {
                // ...
            },
        );
    },
);

Creates and starts the container configured by this context using the given shell command.

The CNB lifecycle launcher will be implicitly used. Environment variables will be set. Uses bash as the shell.

See: CNB App Developer Guide: Run a multi-process app - User-provided shell process

Example
use libcnb_test::{TestConfig, TestRunner};

TestRunner::default().run_test(
    TestConfig::new("heroku/builder:22", "test-fixtures/app"),
    |context| {
        context
            .prepare_container()
            .start_with_shell_command("env", |container| {
                // ...
            });
    },
);

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more