pub struct ContainerAsync<I>where
I: Image,{ /* private fields */ }Expand description
Represents a running docker container that has been started using an async client.
Containers have a custom destructor that removes them as soon as they
go out of scope. However, async drop is not available in rust yet. This implementation
is using block_on.
use testcontainers::*;
#[tokio::test]
async fn a_test() {
let container = MyImage::default().start().await.unwrap();
// Docker container is stopped/removed at the end of this scope.
}Implementations§
Source§impl<I> ContainerAsync<I>where
I: Image,
impl<I> ContainerAsync<I>where
I: Image,
pub async fn ports(&self) -> Result<Ports, TestcontainersError>
Sourcepub async fn get_host_port_ipv4(
&self,
internal_port: impl Into<ContainerPort>,
) -> Result<u16, TestcontainersError>
pub async fn get_host_port_ipv4( &self, internal_port: impl Into<ContainerPort>, ) -> Result<u16, TestcontainersError>
Returns the mapped host port for an internal port of this docker container, on the host’s IPv4 interfaces.
By default, u16 is considered as TCP port. Also, you can convert u16 to ContainerPort port
by using crate::core::IntoContainerPort trait.
This method does not magically expose the given port, it simply performs a mapping on the already exposed ports. If a docker container does not expose a port, this method will return an error.
Sourcepub async fn get_host_port_ipv6(
&self,
internal_port: impl Into<ContainerPort>,
) -> Result<u16, TestcontainersError>
pub async fn get_host_port_ipv6( &self, internal_port: impl Into<ContainerPort>, ) -> Result<u16, TestcontainersError>
Returns the mapped host port for an internal port of this docker container, on the host’s IPv6 interfaces.
By default, u16 is considered as TCP port. Also, you can convert u16 to ContainerPort port
by using crate::core::IntoContainerPort trait.
This method does not magically expose the given port, it simply performs a mapping on the already exposed ports. If a docker container does not expose a port, this method will return an error.
Sourcepub async fn get_bridge_ip_address(&self) -> Result<IpAddr, TestcontainersError>
pub async fn get_bridge_ip_address(&self) -> Result<IpAddr, TestcontainersError>
Returns the bridge ip address of docker container as specified in NetworkSettings.Networks.IPAddress
Sourcepub async fn get_host(&self) -> Result<Host, TestcontainersError>
pub async fn get_host(&self) -> Result<Host, TestcontainersError>
Returns the host that this container may be reached on (may not be the local machine) Suitable for use in URL
Sourcepub async fn exec(
&self,
cmd: ExecCommand,
) -> Result<ExecResult, TestcontainersError>
pub async fn exec( &self, cmd: ExecCommand, ) -> Result<ExecResult, TestcontainersError>
Executes a command in the container.
Sourcepub async fn start(&self) -> Result<(), TestcontainersError>
pub async fn start(&self) -> Result<(), TestcontainersError>
Starts the container.
Sourcepub async fn stop(&self) -> Result<(), TestcontainersError>
pub async fn stop(&self) -> Result<(), TestcontainersError>
Stops the container (not the same with pause).
Sourcepub async fn rm(self) -> Result<(), TestcontainersError>
pub async fn rm(self) -> Result<(), TestcontainersError>
Removes the container.
Sourcepub fn stdout(&self, follow: bool) -> Pin<Box<dyn AsyncBufRead + Send>>
pub fn stdout(&self, follow: bool) -> Pin<Box<dyn AsyncBufRead + Send>>
Returns an asynchronous reader for stdout.
Accepts a boolean parameter to follow the logs:
- pass
trueto read logs from the moment the container starts until it stops (returns I/O error with kindUnexpectedEofif container removed). - pass
falseto read logs from startup to present.
Sourcepub fn stderr(&self, follow: bool) -> Pin<Box<dyn AsyncBufRead + Send>>
pub fn stderr(&self, follow: bool) -> Pin<Box<dyn AsyncBufRead + Send>>
Returns an asynchronous reader for stderr.
Accepts a boolean parameter to follow the logs:
- pass
trueto read logs from the moment the container starts until it stops (returns I/O error withUnexpectedEofif container removed). - pass
falseto read logs from startup to present.
Sourcepub async fn stdout_to_vec(&self) -> Result<Vec<u8>, TestcontainersError>
pub async fn stdout_to_vec(&self) -> Result<Vec<u8>, TestcontainersError>
Returns stdout as a vector of bytes available at the moment of call (from container startup to present).
If you want to read stdout in asynchronous manner, use ContainerAsync::stdout instead.
Sourcepub async fn stderr_to_vec(&self) -> Result<Vec<u8>, TestcontainersError>
pub async fn stderr_to_vec(&self) -> Result<Vec<u8>, TestcontainersError>
Returns stderr as a vector of bytes available at the moment of call (from container startup to present).
If you want to read stderr in asynchronous manner, use ContainerAsync::stderr instead.
Trait Implementations§
Source§impl DbConnection for ContainerAsync<DbContainer>
impl DbConnection for ContainerAsync<DbContainer>
async fn connection_url(&self) -> Result<String, TestcontainersError>
Source§impl<I> Debug for ContainerAsync<I>
impl<I> Debug for ContainerAsync<I>
Auto Trait Implementations§
impl<I> Freeze for ContainerAsync<I>where
I: Freeze,
impl<I> !RefUnwindSafe for ContainerAsync<I>
impl<I> Send for ContainerAsync<I>
impl<I> Sync for ContainerAsync<I>
impl<I> Unpin for ContainerAsync<I>where
I: Unpin,
impl<I> !UnwindSafe for ContainerAsync<I>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more