33 releases (10 breaking)

0.14.0-beta.1 Jun 19, 2023
0.11.3 Oct 17, 2024
0.11.2 Sep 30, 2024
0.9.0 Jul 30, 2024
0.1.0-beta.1 Jun 28, 2023

#23 in Testing

Download history 13450/week @ 2024-07-18 12636/week @ 2024-07-25 15610/week @ 2024-08-01 15644/week @ 2024-08-08 17388/week @ 2024-08-15 15057/week @ 2024-08-22 18102/week @ 2024-08-29 18584/week @ 2024-09-05 15982/week @ 2024-09-12 13885/week @ 2024-09-19 18759/week @ 2024-09-26 15072/week @ 2024-10-03 14747/week @ 2024-10-10 18496/week @ 2024-10-17 17887/week @ 2024-10-24 16912/week @ 2024-10-31

71,017 downloads per month
Used in 42 crates (39 directly)

MIT license

235KB
4.5K 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 postgres features enabled):

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

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

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::ImageExt;

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::{ContainerRequest, ImageExt}
};


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

License

Dependencies

~24–40MB
~754K SLoC