1 unstable release

Uses new Rust 2024

new 0.1.0 Apr 5, 2025

#400 in Unix APIs

45 downloads per month

MIT license

19KB
106 lines

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

Dependencies

~22–36MB
~657K SLoC