#test-containers #docker #env-var #runner

dev testcontainers-modules

Community maintained modules for Testcontainers for Rust

27 releases (7 breaking)

0.14.0-beta.1 Jun 19, 2023
0.8.0 Jul 7, 2024
0.7.1 Jun 30, 2024
0.3.6 Mar 22, 2024
0.1.0-beta.1 Jun 28, 2023

#37 in Testing

Download history 6624/week @ 2024-03-31 7336/week @ 2024-04-07 7137/week @ 2024-04-14 6337/week @ 2024-04-21 6876/week @ 2024-04-28 8907/week @ 2024-05-05 9908/week @ 2024-05-12 9167/week @ 2024-05-19 8297/week @ 2024-05-26 9591/week @ 2024-06-02 9202/week @ 2024-06-09 11854/week @ 2024-06-16 12213/week @ 2024-06-23 10567/week @ 2024-06-30 14372/week @ 2024-07-07 14759/week @ 2024-07-14

52,490 downloads per month
Used in 33 crates

MIT license

150KB
3.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

~22–37MB
~687K SLoC