Skip to content

Commit

Permalink
feat!: container-centric API
Browse files Browse the repository at this point in the history
Quite large refactoring as part of project revamp #563, and also the long-awaited refactoring #386

Closes #386
Closes #326
Closes #475
Closes #508
Closes #392
Closes #561
Closes #559

MSRV was bumped to `1.70` in order to use `std::sync::OnceLock`. This should NOT be a problem, tests usually executed on more recent versions (also see [this ref](https://github.com/testcontainers/testcontainers-rs/pull/503/files#r1242651354)).
  • Loading branch information
DDtKey committed Apr 18, 2024
1 parent cd8a3e5 commit ae9f585
Show file tree
Hide file tree
Showing 26 changed files with 1,587 additions and 1,695 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ members = [
authors = ["CoBloX developers <team@coblox.tech>"]
edition = "2021"
license = "MIT OR Apache-2.0"
rust-version = "1.66"
rust-version = "1.70"

[workspace.dependencies]
testimages = { path = "testimages" }
37 changes: 36 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,42 @@ The crate provides an API for working with containers in a test environment.

1. Depend on `testcontainers`
2. Implement `testcontainers::core::Image` for necessary docker-images
3. Run it with any available client `testcontainers::clients::*`
3. Run it with any available runner `testcontainers::core::runners::*` (use `blocking` feature for blocking API)

#### Example:

- Blocking API (under `blocking` feature)
```rust
use testcontainers::{
GenericImage,
core::{WaitFor, runners::SyncRunner}
};

#[test]
fn test_redis() {
let container = GenericImage::new("redis", "latest")
.with_exposed_port(6379)
.with_wait_for(WaitFor::message_on_stdout("Ready to accept connections"))
.start();
}
```

- Async API
```rust
use testcontainers::{
GenericImage,
core::{WaitFor, runners::AsyncRunner}
};

#[tokio::test]
async fn test_redis() {
let container = GenericImage::new("redis", "latest")
.with_exposed_port(6379)
.with_wait_for(WaitFor::message_on_stdout("Ready to accept connections"))
.start()
.await;
}
```

### Ready-to-use images

Expand Down
17 changes: 9 additions & 8 deletions testcontainers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,29 @@ edition = "2021"
keywords = ["docker", "testcontainers"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/testcontainers/testcontainers-rs"
rust-version = "1.70.0"
description = "A library for integration-testing against docker containers from within Rust."

[dependencies]
async-trait = { version = "0.1", optional = true }
bollard = { version = "0.16.1", optional = true }
async-trait = { version = "0.1" }
bollard = { version = "0.16.1", features = ["ssl"] }
bollard-stubs = "=1.44.0-rc.2"
conquer-once = { version = "0.4", optional = true }
dirs = "5.0.1"
futures = "0.3"
hex = "0.4"
hmac = "0.12"
log = "0.4"
rand = "0.8"
serde = { version = "1", features = ["derive"] }
serde-java-properties = "0.1.1"
serde_json = "1"
sha2 = "0.10"
serde_with = "3.7.0"
signal-hook = { version = "0.3", optional = true }
tokio = { version = "1", features = ["macros"], optional = true }
tokio = { version = "1", features = ["macros"] }
tokio-util = "0.7.10"
url = { version = "2", features = ["serde"] }

[features]
default = []
experimental = ["async-trait", "bollard", "tokio"]
blocking = []
watchdog = ["signal-hook", "conquer-once"]

[dev-dependencies]
Expand Down
10 changes: 0 additions & 10 deletions testcontainers/src/clients.rs

This file was deleted.

Loading

0 comments on commit ae9f585

Please sign in to comment.