Struct libcnb_test::ContainerConfig

source ·
pub struct ContainerConfig { /* private fields */ }
Expand description

Config used when starting a container.

By default the container will run the CNB default process-type, however this can be overridden using ContainerConfig::entrypoint and ContainerConfig::command. See: CNB App Developer Guide: Run a multi-process app

§Example

use libcnb_test::{BuildConfig, ContainerConfig, TestRunner};

TestRunner::default().build(
    BuildConfig::new("heroku/builder:22", "tests/fixtures/app"),
    |context| {
        // ...
        context.start_container(
            ContainerConfig::new()
                .env("PORT", "12345")
                .expose_port(12345),
            |container| {
                // ...
            },
        );
    },
);

Implementations§

source§

impl ContainerConfig

source

pub fn new() -> Self

Creates an empty ContainerConfig instance.

By default the container will run the CNB default process-type, however this can be overridden using ContainerConfig::entrypoint and ContainerConfig::command. See: CNB App Developer Guide: Run a multi-process app

§Example
use libcnb_test::{BuildConfig, ContainerConfig, TestRunner};

TestRunner::default().build(
    BuildConfig::new("heroku/builder:22", "tests/fixtures/app"),
    |context| {
        // ...
        context.start_container(
            ContainerConfig::new()
                .env("PORT", "12345")
                .expose_port(12345),
            |container| {
                // ...
            },
        );
    },
);
source

pub fn entrypoint(&mut self, entrypoint: impl Into<String>) -> &mut Self

Override the image’s entrypoint (which is the CNB default process-type).

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

§Example
use libcnb_test::{BuildConfig, ContainerConfig, TestRunner};

TestRunner::default().build(
    BuildConfig::new("heroku/builder:22", "tests/fixtures/app"),
    |context| {
        // ...
        context.start_container(ContainerConfig::new().entrypoint("worker"), |container| {
            // ...
        });
    },
);
source

pub fn command<I: IntoIterator<Item = S>, S: Into<String>>( &mut self, command: I ) -> &mut Self

Set the container’s command (CNB images have no default command).

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

§Example
use libcnb_test::{BuildConfig, ContainerConfig, TestRunner};

TestRunner::default().build(
    BuildConfig::new("heroku/builder:22", "tests/fixtures/app"),
    |context| {
        // ...
        context.start_container(
            ContainerConfig::new().command(["--additional-arg1", "--additional-arg2"]),
            |container| {
                // ...
            },
        );
    },
);
source

pub fn expose_port(&mut self, port: u16) -> &mut Self

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 crate::ContainerContext::address_for_port to obtain the local port for a mapped port.

§Example
use libcnb_test::{BuildConfig, ContainerConfig, TestRunner};

TestRunner::default().build(
    BuildConfig::new("heroku/builder:22", "tests/fixtures/app"),
    |context| {
        // ...
        context.start_container(
            ContainerConfig::new()
                .env("PORT", "12345")
                .expose_port(12345),
            |container| {
                let address_on_host = container.address_for_port(12345);
                // ...
            },
        );
    },
);
source

pub fn env( &mut self, key: impl Into<String>, value: impl Into<String> ) -> &mut Self

Inserts or updates an environment variable mapping for the container.

§Example
use libcnb_test::{BuildConfig, ContainerConfig, TestRunner};

TestRunner::default().build(
    BuildConfig::new("heroku/builder:22", "tests/fixtures/app"),
    |context| {
        // ...
        context.start_container(
            ContainerConfig::new()
                .env("PORT", "5678")
                .env("DEBUG", "true"),
            |container| {
                // ...
            },
        );
    },
);
source

pub fn envs<K: Into<String>, V: Into<String>, I: IntoIterator<Item = (K, V)>>( &mut self, envs: I ) -> &mut Self

Adds or updates multiple environment variable mappings for the container.

§Example
use libcnb_test::{BuildConfig, ContainerConfig, TestRunner};

TestRunner::default().build(
    BuildConfig::new("heroku/builder:22", "tests/fixtures/app"),
    |context| {
        // ...
        context.start_container(
            ContainerConfig::new().envs([("PORT", "5678"), ("DEBUG", "true")]),
            |container| {
                // ...
            },
        );
    },
);

Trait Implementations§

source§

impl Clone for ContainerConfig

source§

fn clone(&self) -> ContainerConfig

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Default for ContainerConfig

source§

fn default() -> ContainerConfig

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.