pub struct ContainerContext<'a> {
    pub container_name: String,
    /* private fields */
}
Expand description

Context of a launched container.

Fields

container_name: String

The randomly generated name of this container.

Implementations

Gets the container’s log output until the current point in time.

Note: This method will only return logs until the current point in time. It will not block until the container stops. Since the output of this method depends on timing, directly asserting on its contents might result in flaky tests.

See: logs_wait for a blocking alternative.

Example
use libcnb_test::{assert_contains, TestConfig, TestRunner};

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

Gets the container’s log output until the container stops.

Note: This method will block until the container stops. If the container never stops by itself, your test will hang indefinitely. This is common when the container hosts an HTTP service.

See: logs_now for a non-blocking alternative.

Example
use libcnb_test::{assert_contains, TestConfig, TestRunner};

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

Returns the local address of an exposed container port.

Example
use libcnb_test::{TestConfig, TestRunner};

TestRunner::default().run_test(
    TestConfig::new("heroku/builder:22", "test-fixtures/app"),
    |context| {
        // ...
        context
            .prepare_container()
            .expose_port(12345)
            .start_with_default_process(|container| {
                assert_eq!(
                    call_test_fixture_service(
                        container.address_for_port(12345).unwrap(),
                        "Hagbard Celine"
                    )
                    .unwrap(),
                    "enileC drabgaH"
                );
            });
    },
);

Executes a shell command inside an already running container.

Example
use libcnb_test::{assert_contains, TestConfig, TestRunner};

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

Trait Implementations

Executes the destructor for this type. Read more

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