testcontainers-ext

Crates.iotestcontainers-ext
lib.rstestcontainers-ext
version0.1.0
created_at2025-04-05 11:25:44.20608+00
updated_at2025-04-05 11:25:44.20608+00
descriptionUtilities collection of extension traits for testcontainers-rs.
homepage
repositoryhttps://github.com/lonelyhentxi/testcontainers-rs-ext
max_upload_size
id1622040
size67,079
Zhou Yeheng (lonelyhentxi)

documentation

README

Testcontainers-ext

Crates.io Docs.rs

Testcontainers-ext is a utilities collection of extension traits for testcontainers-rs.

Install

# or cargo add testcontainers-ext
cargo install testcontainers-ext

Usage

  • ImagePruneExistedLabelExt / with_prune_existed_label
use testcontainers::{core::{IntoContainerPort, WaitFor}, runners::SyncRunner, GenericImage, ImageExt};
use testcontainers_ext::ImagePruneExistedLabelExt;
use anyhow::Result;

#[tokio::test]
async fn test () -> Result<()> {
    let container = GenericImage::new("redis", "7.2.4")
        .with_exposed_port(6379.tcp())
        .with_wait_for(WaitFor::message_on_stdout("Ready to accept connections"))
        .with_prune_existed_label(
            "my-project-scope",
            "redis",
            true,
            true
        ).await?
        .start()
        .await?;
    Ok(())
}
  • ImageDefaultLogConsumerExt / with_default_log_consumer
use testcontainers::{core::{IntoContainerPort, WaitFor}, runners::SyncRunner, GenericImage, ImageExt};
use testcontainers_rs_ext::ImageDefaultLogConsumerExt;
use anyhow::Result;

#[tokio::test]
async fn test () -> Result<()> {
    let container = GenericImage::new("redis", "7.2.4")
        .with_exposed_port(6379.tcp())
        .with_wait_for(WaitFor::message_on_stdout("Ready to accept connections"))
        .with_default_log_consumer()
        .start()
        .await?;
    Ok(())
}

Ready-to-use images

The easiest way to use testcontainers is to depend on ready-to-use images (aka modules).

Modules are available as a community-maintained crate: testcontainers-modules

License

Licensed under

Commit count: 4

cargo fmt