Struct libcnb_test::PrepareContainerContext
source · [−]pub struct PrepareContainerContext<'a> { /* private fields */ }Implementations
sourceimpl<'a> PrepareContainerContext<'a>
impl<'a> PrepareContainerContext<'a>
sourcepub fn expose_port(&mut self, port: u16) -> &mut Self
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
ContainerContext::address_for_port to obtain the local port for a mapped port.
sourcepub fn env(
&mut self,
key: impl Into<String>,
value: impl Into<String>
) -> &mut Self
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::{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| {
// ...
})
},
);sourcepub fn envs<K: Into<String>, V: Into<String>, I: IntoIterator<Item = (K, V)>>(
&mut self,
envs: I
) -> &mut Self
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::{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| {
// ...
})
},
);sourcepub fn start_with_default_process<F: FnOnce(ContainerContext<'_>)>(&self, f: F)
pub fn start_with_default_process<F: FnOnce(ContainerContext<'_>)>(&self, f: F)
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
Panics
- When the container could not be created
- When the container could not be started
sourcepub fn start_with_default_process_args<F: FnOnce(ContainerContext<'_>), A: IntoIterator<Item = I>, I: Into<String>>(
&self,
args: A,
f: F
)
pub fn start_with_default_process_args<F: FnOnce(ContainerContext<'_>), A: IntoIterator<Item = I>, I: Into<String>>(
&self,
args: A,
f: F
)
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
Panics
- When the container could not be created
- When the container could not be started
sourcepub fn start_with_process<F: FnOnce(ContainerContext<'_>), P: Into<String>>(
&self,
process: P,
f: F
)
pub fn start_with_process<F: FnOnce(ContainerContext<'_>), P: Into<String>>(
&self,
process: P,
f: F
)
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
Panics
- When the container could not be created
- When the container could not be started
sourcepub fn start_with_process_args<F: FnOnce(ContainerContext<'_>), A: IntoIterator<Item = I>, I: Into<String>, P: Into<String>>(
&self,
process: P,
args: A,
f: F
)
pub fn start_with_process_args<F: FnOnce(ContainerContext<'_>), A: IntoIterator<Item = I>, I: Into<String>, P: Into<String>>(
&self,
process: P,
args: A,
f: F
)
Creates and starts the container configured by this context using the given CNB process and arguments.
Panics
- When the container could not be created
- When the container could not be started
sourcepub fn start_with_shell_command<F: FnOnce(ContainerContext<'_>), C: Into<String>>(
&self,
command: C,
f: F
)
pub fn start_with_shell_command<F: FnOnce(ContainerContext<'_>), C: Into<String>>(
&self,
command: C,
f: F
)
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
/bin/sh as the shell.
See: CNB App Developer Guide: Run a multi-process app - User-provided shell process
Panics
- When the container could not be created
- When the container could not be started
Auto Trait Implementations
impl<'a> !RefUnwindSafe for PrepareContainerContext<'a>
impl<'a> !Send for PrepareContainerContext<'a>
impl<'a> !Sync for PrepareContainerContext<'a>
impl<'a> Unpin for PrepareContainerContext<'a>
impl<'a> !UnwindSafe for PrepareContainerContext<'a>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber to this type, returning a
WithDispatch wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber to this type, returning a
WithDispatch wrapper. Read more