Struct testcontainers::core::ContainerAsync

source ·
pub struct ContainerAsync<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,

source

pub fn id(&self) -> &str

Returns the id of this container.

source

pub fn image(&self) -> &I

Returns a reference to the Image of this container.

source

pub async fn ports(&self) -> Result<Ports>

source

pub async fn get_host_port_ipv4( &self, internal_port: impl Into<ContainerPort>, ) -> Result<u16>

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.

source

pub async fn get_host_port_ipv6( &self, internal_port: impl Into<ContainerPort>, ) -> Result<u16>

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.

source

pub async fn get_bridge_ip_address(&self) -> Result<IpAddr>

Returns the bridge ip address of docker container as specified in NetworkSettings.Networks.IPAddress

source

pub async fn get_host(&self) -> Result<Host>

Returns the host that this container may be reached on (may not be the local machine) Suitable for use in URL

source

pub async fn exec(&self, cmd: ExecCommand) -> Result<ExecResult>

Executes a command in the container.

source

pub async fn start(&self) -> Result<()>

Starts the container.

source

pub async fn stop(&self) -> Result<()>

Stops the container (not the same with pause).

source

pub async fn rm(self) -> Result<()>

Removes the container.

source

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 true to read logs from the moment the container starts until it stops (returns I/O error with kind UnexpectedEof if container removed).
  • pass false to read logs from startup to present.
source

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 true to read logs from the moment the container starts until it stops (returns I/O error with UnexpectedEof if container removed).
  • pass false to read logs from startup to present.
source

pub async fn stdout_to_vec(&self) -> Result<Vec<u8>>

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.

source

pub async fn stderr_to_vec(&self) -> Result<Vec<u8>>

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<I> Debug for ContainerAsync<I>
where I: Debug + Image,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<I> Drop for ContainerAsync<I>
where I: Image,

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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> 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> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
source§

impl<T> IntoResult<T> for T

§

type Err = Infallible

source§

fn into_result(self) -> Result<T, <T as IntoResult<T>>::Err>

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.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

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
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more