pub trait Image{
// 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
Required Methods§
sourcefn tag(&self) -> &str
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.
sourcefn ready_conditions(&self) -> Vec<WaitFor>
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§
sourcefn env_vars(
&self,
) -> impl IntoIterator<Item = (impl Into<Cow<'_, str>>, impl Into<Cow<'_, str>>)>
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.
sourcefn mounts(&self) -> impl IntoIterator<Item = &Mount>
fn mounts(&self) -> impl IntoIterator<Item = &Mount>
Returns the mounts that needs to be created when a container is created.
sourcefn copy_to_sources(&self) -> impl IntoIterator<Item = &CopyToContainer>
fn copy_to_sources(&self) -> impl IntoIterator<Item = &CopyToContainer>
Returns the files to be copied into the container at startup.
sourcefn entrypoint(&self) -> Option<&str>
fn entrypoint(&self) -> Option<&str>
Returns the entrypoint this image needs to be created with.
sourcefn cmd(&self) -> impl IntoIterator<Item = impl Into<Cow<'_, str>>>
fn cmd(&self) -> impl IntoIterator<Item = impl Into<Cow<'_, str>>>
Returns the CMD
this image needs to be created with.
sourcefn expose_ports(&self) -> &[ContainerPort]
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.
sourcefn exec_after_start(
&self,
cs: ContainerState,
) -> Result<Vec<ExecCommand>, TestcontainersError>
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.