20 unstable releases (3 breaking)

0.14.0-beta.1 Jun 19, 2023
0.4.3 May 12, 2024
0.4.0 Apr 27, 2024
0.3.6 Mar 22, 2024
0.1.0-beta.1 Jun 28, 2023

#28 in Testing

Download history 4312/week @ 2024-01-26 3477/week @ 2024-02-02 2368/week @ 2024-02-09 3065/week @ 2024-02-16 3850/week @ 2024-02-23 5612/week @ 2024-03-01 5346/week @ 2024-03-08 5460/week @ 2024-03-15 5861/week @ 2024-03-22 6819/week @ 2024-03-29 7734/week @ 2024-04-05 7216/week @ 2024-04-12 6369/week @ 2024-04-19 6239/week @ 2024-04-26 9122/week @ 2024-05-03 6920/week @ 2024-05-10

29,655 downloads per month
Used in 25 crates (24 directly)

MIT license

125KB
3K SLoC

testcontainers-modules

Continuous Integration Crates.io Docs.rs

Community maintained modules for testcontainers

Provides modules to use for testing components in accordance with testcontainers-rs. Every module is treated as a feature inside this crate.

Usage

  1. Depend on testcontainers-modules with necessary features (e.g postgres, minio and etc)
    • Enable blocking feature if you want to use modules within synchronous tests (feature-gate for SyncRunner)
  2. Then start using the modules inside your tests with either AsyncRunner or SyncRunner

Simple example of using postgres module with SyncRunner (blocking and posrges features enabled):

use testcontainers_modules::{postgres, testcontainers::runners::SyncRunner};

#[test]
fn test_with_postgres() {
    let container = postgres::Postgres::default().start();
    let host_ip = container.get_host();
    let host_port = container.get_host_port_ipv4(5432);
}

Note: you don't need to explicitly depend on testcontainers as it's re-exported dependency of testcontainers-modules with aligned version between these crates. For example:

use testcontainers_modules::testcontainers::RunnableImage;

You can also see examples for more details.

How to override module defaults (version, tag, ENV-variables)

Just use RunnableImage:

use testcontainers_modules::{
    redis::Redis,
    testcontainers::RunnableImage
};


/// Create a Redis module with `6.2-alpine` tag and custom password
fn create_redis() -> RunnableImage<Redis> {
    RunnableImage::from(Redis::default())
        .with_tag("6.2-alpine")
        .with_env_var(("REDIS_PASSWORD", "my_secret_password"))
}

License

Dependencies

~21–34MB
~632K SLoC