testcontainers::core

Trait Image

source
pub trait Image
where Self: Sized + Sync + Send,
{ // Required methods fn name(&self) -> &str; fn tag(&self) -> &str; fn ready_conditions(&self) -> Vec<WaitFor>; // Provided methods fn env_vars( &self, ) -> impl IntoIterator<Item = (impl Into<Cow<'_, str>>, impl Into<Cow<'_, str>>)> { ... } fn mounts(&self) -> impl IntoIterator<Item = &Mount> { ... } fn copy_to_sources(&self) -> impl IntoIterator<Item = &CopyToContainer> { ... } fn entrypoint(&self) -> Option<&str> { ... } fn cmd(&self) -> impl IntoIterator<Item = impl Into<Cow<'_, str>>> { ... } fn expose_ports(&self) -> &[ContainerPort] { ... } fn exec_after_start( &self, cs: ContainerState, ) -> Result<Vec<ExecCommand>, TestcontainersError> { ... } }
Expand description

Represents a docker image.

Implementations are required to implement Default. The default instance of an Image should have a meaningful configuration! It should be possible to run the default instance of an Image and get back a working container!

Required Methods§

source

fn name(&self) -> &str

The name of the docker image to pull from the Docker Hub registry.

source

fn tag(&self) -> &str

Implementations are encouraged to include a tag that will not change (i.e. NOT latest) in order to prevent test code from randomly breaking because the underlying docker suddenly changed.

source

fn ready_conditions(&self) -> Vec<WaitFor>

Returns a list of conditions that need to be met before a started container is considered ready.

This method is the 🍞 and butter of the whole testcontainers library. Containers are rarely instantly available as soon as they are started. Most of them take some time to boot up.

The conditions returned from this method are evaluated in the order they are returned. Therefore you most likely want to start with a WaitFor::Log or WaitFor::Http.

Provided Methods§

source

fn env_vars( &self, ) -> impl IntoIterator<Item = (impl Into<Cow<'_, str>>, impl Into<Cow<'_, str>>)>

Returns the environment variables that needs to be set when a container is created.

source

fn mounts(&self) -> impl IntoIterator<Item = &Mount>

Returns the mounts that needs to be created when a container is created.

source

fn copy_to_sources(&self) -> impl IntoIterator<Item = &CopyToContainer>

Returns the files to be copied into the container at startup.

source

fn entrypoint(&self) -> Option<&str>

Returns the entrypoint this image needs to be created with.

source

fn cmd(&self) -> impl IntoIterator<Item = impl Into<Cow<'_, str>>>

Returns the CMD this image needs to be created with.

source

fn expose_ports(&self) -> &[ContainerPort]

Returns the ports that needs to be exposed when a container is created.

This method is useful when there is a need to expose some ports, but there is no EXPOSE instruction in the Dockerfile of an image.

source

fn exec_after_start( &self, cs: ContainerState, ) -> Result<Vec<ExecCommand>, TestcontainersError>

Returns the commands that needs to be executed after a container is started i.e. commands to be run in a running container.

Notice, that you can return an error from this method, for example if container’s state is unexpected. In this case, you can use TestcontainersError::other to wrap an arbitrary error.

This method is useful when certain re-configuration is required after the start of container for the container to be considered ready for use in tests.

Object Safety§

This trait is not object safe.

Implementors§