Skip to content

Commit

Permalink
Put reqwest behind http_wait feature
Browse files Browse the repository at this point in the history
  • Loading branch information
rukai committed Jul 22, 2024
1 parent eae71c6 commit 38c7864
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 10 deletions.
81 changes: 79 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,86 +3,120 @@
All notable changes to this project will be documented in this file.

## [0.20.1] - 2024-07-18

### Details

#### Bug Fixes

- Trim newline char from the mirrored messages ([#699](https://github.com/testcontainers/testcontainers-rs/pull/699))

#### Features

- Support optional prefix for `LoggingConsumer` ([#698](https://github.com/testcontainers/testcontainers-rs/pull/698))

## [0.20.0] - 2024-07-07

### Details

#### Bug Fixes

- [] Drop `Clone` impl for `ContainerRequest` ([#680](https://github.com/testcontainers/testcontainers-rs/pull/680))
- Exclude image pulling time from startup timeout ([#687](https://github.com/testcontainers/testcontainers-rs/pull/687))
- Waiting for mutiple messages from the same log frame ([#688](https://github.com/testcontainers/testcontainers-rs/pull/688))
- Pass correct log-source for `stderr` wait strategy ([#692](https://github.com/testcontainers/testcontainers-rs/pull/692))

#### Features

- Introduce log consumers ([#681](https://github.com/testcontainers/testcontainers-rs/pull/681))
- Introduce `LoggingConsumer` based on `log` crate ([#682](https://github.com/testcontainers/testcontainers-rs/pull/682))
- [] Enhance `LogWaitStrategy` to wait for message appearance multiple times ([#683](https://github.com/testcontainers/testcontainers-rs/pull/683))
- [] Introduce `ExitWaitStrategy` ([#684](https://github.com/testcontainers/testcontainers-rs/pull/684))

#### Miscellaneous Tasks

- Get rid of outdated variables naming ([#679](https://github.com/testcontainers/testcontainers-rs/pull/679))
- Relax log level for log producer error ([#685](https://github.com/testcontainers/testcontainers-rs/pull/685))
- Re-configure blocking runtime ([#690](https://github.com/testcontainers/testcontainers-rs/pull/690))

#### Performance

- Avoid spawning log producer without consumers ([#689](https://github.com/testcontainers/testcontainers-rs/pull/689))

#### Refactor

- Internal log processing structures ([#678](https://github.com/testcontainers/testcontainers-rs/pull/678))

#### Styling

- Apply clippy suggestion ([#693](https://github.com/testcontainers/testcontainers-rs/pull/693))

## [0.19.0] - 2024-06-27

### Details

#### Bug Fixes

- [] Use `rustls-tls` as default for `reqwest` ([#672](https://github.com/testcontainers/testcontainers-rs/pull/672))

#### Documentation

- Update examples of `GenericImage::with_exposed_port` ([#670](https://github.com/testcontainers/testcontainers-rs/pull/670))

#### Features

- Add ability to convert `ContainerPort` to `u16` ([#664](https://github.com/testcontainers/testcontainers-rs/pull/664))

#### Miscellaneous Tasks

- Make `ports` module public ([#665](https://github.com/testcontainers/testcontainers-rs/pull/665))

#### Performance

- Use separate dropper thread for `current_thread` flavor ([#666](https://github.com/testcontainers/testcontainers-rs/pull/666))

#### Refactor

- Use multi-threaded runtime for blocking feature ([#667](https://github.com/testcontainers/testcontainers-rs/pull/667))

## [0.18.0] - 2024-06-15

### Details

#### Bug Fixes

- [] Make `DOCKER_CONFIG` usage consistent with Docker CLI ([#654](https://github.com/testcontainers/testcontainers-rs/pull/654))

#### Features

- [] Support UDP and SCTP port mappings ([#655](https://github.com/testcontainers/testcontainers-rs/pull/655))
- Impl `From<u16>` for `ContainerPort` with TCP default ([#658](https://github.com/testcontainers/testcontainers-rs/pull/658))
- Support HTTP wait strategy ([#659](https://github.com/testcontainers/testcontainers-rs/pull/659))
- Allow passing `u16` to `Ports`

#### Miscellaneous Tasks

- Use nightly `rustfmt` ([#657](https://github.com/testcontainers/testcontainers-rs/pull/657))

#### Refactor

- [] Get rid of associated type `ImageArgs` and rename to `cmd` ([#649](https://github.com/testcontainers/testcontainers-rs/pull/649))
- Avoid unnecessary owned structs and boxing ([#651](https://github.com/testcontainers/testcontainers-rs/pull/651))
- [] Add `ImageExt` trait to avoid explicit conversion to `RunnableImage` ([#652](https://github.com/testcontainers/testcontainers-rs/pull/652))
- [] Rename `RunnableImage` to `ContainerRequest` ([#653](https://github.com/testcontainers/testcontainers-rs/pull/653))
- [] Exposed and mapped ports api ([#656](https://github.com/testcontainers/testcontainers-rs/pull/656))
- Preliminary refactoring of `wait` strategies ([#661](https://github.com/testcontainers/testcontainers-rs/pull/661))

## [0.17.0] - 2024-05-26

### Details

#### Bug Fixes

- Collect bridge IP address correctly ([#626](https://github.com/testcontainers/testcontainers-rs/pull/626))
- Replace missed panics with `Result` ([#638](https://github.com/testcontainers/testcontainers-rs/pull/638))

#### Features

- Impl `Error` for `WaitError` ([#629](https://github.com/testcontainers/testcontainers-rs/pull/629))
- [] Extend `exec` interface to return logs and exec code ([#631](https://github.com/testcontainers/testcontainers-rs/pull/631))
- Ability to access container logs ([#633](https://github.com/testcontainers/testcontainers-rs/pull/633))
Expand All @@ -94,81 +128,124 @@ All notable changes to this project will be documented in this file.
- [] Add container startup timeout with default of 1 minute ([#643](https://github.com/testcontainers/testcontainers-rs/pull/643))

#### Miscellaneous Tasks

- Fix clippy warning without features enabled ([#632](https://github.com/testcontainers/testcontainers-rs/pull/632))

#### Refactor

- [] Drop re-export of `CgroupnsMode` accessible through `core` ([#630](https://github.com/testcontainers/testcontainers-rs/pull/630))
- [] Drop previously deprecated `get_host_ip_address` ([#628](https://github.com/testcontainers/testcontainers-rs/pull/628))
- [] Return `PortNotExposed` error from `ContainerState::host_port_*` ([#644](https://github.com/testcontainers/testcontainers-rs/pull/644))

## [0.16.7] - 2024-05-01

### Details

#### Bug Fixes

- `get_host` for `unix` and `npipe` docker hosts ([#621](https://github.com/testcontainers/testcontainers-rs/pull/621))

#### Features

- Extend `WaitFor` for `ExecCommand` ([#622](https://github.com/testcontainers/testcontainers-rs/pull/622))

## [0.16.6] - 2024-04-30

### Details

#### Features

- Add `get_host` to `Container` and deprecate `get_host_ip_address` ([#618](https://github.com/testcontainers/testcontainers-rs/pull/618))
- Allow cgroupns-mode and userns-mode to be configured ([#605](https://github.com/testcontainers/testcontainers-rs/pull/605))

## [0.16.5] - 2024-04-29

### Details

#### Bug Fixes

- Correct drop of a network for sync container ([#612](https://github.com/testcontainers/testcontainers-rs/pull/612))
- Correct default for `get_host_ip_address` in case of `unix` or `npipe` ([#613](https://github.com/testcontainers/testcontainers-rs/pull/613))

#### Miscellaneous Tasks

- Update `serde-java-properties` to `0.2.0` ([#614](https://github.com/testcontainers/testcontainers-rs/pull/614))

## [0.16.4] - 2024-04-29

### Details

#### Bug Fixes

- Properly expose mapped ports ([#610](https://github.com/testcontainers/testcontainers-rs/pull/610))

#### Features

- Introduce `properties-config` cargo feature ([#608](https://github.com/testcontainers/testcontainers-rs/pull/608))
- Support docker auth configuration for image pulling ([#609](https://github.com/testcontainers/testcontainers-rs/pull/609))

## [0.16.3] - 2024-04-27

### Details

#### Bug Fixes

- Expose mount-related types ([#603](https://github.com/testcontainers/testcontainers-rs/pull/603))

## [0.16.2] - 2024-04-27

### Details

#### Documentation

- Fix `docsrs` attributes

## [0.16.1] - 2024-04-27

### Details

#### Documentation

- Add readme to crates.io and fix documentation builds ([#598](https://github.com/testcontainers/testcontainers-rs/pull/598))
- Fix symlink to readme ([#600](https://github.com/testcontainers/testcontainers-rs/pull/600))

## [0.16.0] - 2024-04-27

### Details

#### Bug Fixes

- Use the binds option instead of volumes for mounts ([#581](https://github.com/testcontainers/testcontainers-rs/pull/581))

#### Documentation

- Mention a way to preserve running containers ([#586](https://github.com/testcontainers/testcontainers-rs/pull/586))

#### Features

- Support for docker cli flag `--add-host` ([#547](https://github.com/testcontainers/testcontainers-rs/pull/547))
- Allow to override args in a `RunnableImage` ([#558](https://github.com/testcontainers/testcontainers-rs/pull/558))
- Add `name` parameter to `RunnableImage` ([#549](https://github.com/testcontainers/testcontainers-rs/pull/549))
- [] Container-centric API with refactored underlying layer ([#575](https://github.com/testcontainers/testcontainers-rs/pull/575))
- Add ability to pull-image explicitly ([#579](https://github.com/testcontainers/testcontainers-rs/pull/579))

#### Miscellaneous Tasks

- Remove `spectral` from `dev-dependencies` ([#526](https://github.com/testcontainers/testcontainers-rs/pull/526))
- Update reqwest requirement from 0.11.14 to 0.12.3 ([#569](https://github.com/testcontainers/testcontainers-rs/pull/569))
- Update bollard and bollard-stubs ([#574](https://github.com/testcontainers/testcontainers-rs/pull/574))
- Reuse workspace level configs ([#568](https://github.com/testcontainers/testcontainers-rs/pull/568))

#### Refactor

- [] Api for mounts and volumes ([#596](https://github.com/testcontainers/testcontainers-rs/pull/596))

#### Styling

- Derive `Default` to fix clippy lint ([#525](https://github.com/testcontainers/testcontainers-rs/pull/525))
- Actualize formatting configs ([#567](https://github.com/testcontainers/testcontainers-rs/pull/567))
- Enable `StdExternalCrate` grouping

## [0.15.0] - 2023-09-28

### Added
Expand All @@ -187,9 +264,9 @@ All notable changes to this project will be documented in this file.
### Removed

- Removed all pre-defined images from the library to escape unbounded maintenance work.
See https://github.com/testcontainers/testcontainers-rs/issues/471 for details.
See <https://github.com/testcontainers/testcontainers-rs/issues/471> for details.
- Removed explicit support for podman.
See https://github.com/testcontainers/testcontainers-rs/issues/422 for details.
See <https://github.com/testcontainers/testcontainers-rs/issues/422> for details.

## [0.14.0] - 2022-05-30

Expand Down
3 changes: 2 additions & 1 deletion testcontainers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ log = "0.4"
memchr = "2.7.2"
parse-display = "0.9.0"
pin-project-lite = "0.2.14"
reqwest = { version = "0.12.5", features = ["rustls-tls", "rustls-tls-native-roots", "hickory-dns", "json", "charset", "http2"], default-features = false }
reqwest = { version = "0.12.5", features = ["rustls-tls", "rustls-tls-native-roots", "hickory-dns", "json", "charset", "http2"], default-features = false, optional = true }
serde = { version = "1", features = ["derive"] }
serde-java-properties = { version = "0.2.0", optional = true }
serde_json = "1"
Expand All @@ -45,6 +45,7 @@ url = { version = "2", features = ["serde"] }
default = []
blocking = []
watchdog = ["signal-hook", "conquer-once"]
http_wait = ["reqwest"]
properties-config = ["serde-java-properties"]

[dev-dependencies]
Expand Down
5 changes: 3 additions & 2 deletions testcontainers/src/core/error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::error::Error;

use crate::core::logs::WaitLogError;
pub use crate::core::{client::ClientError, env::ConfigurationError, ContainerPort};
use crate::core::{logs::WaitLogError, wait::http_strategy::HttpWaitError};

pub type Result<T> = std::result::Result<T, TestcontainersError>;

Expand Down Expand Up @@ -55,7 +55,8 @@ pub enum WaitContainerError {
#[error("container state is unavailable")]
StateUnavailable,
#[error("container is not ready: {0}")]
HttpWait(#[from] HttpWaitError),
#[cfg(feature = "http_wait")]
HttpWait(#[from] crate::core::wait::http_strategy::HttpWaitError),
#[error("healthcheck is not configured for container: {0}")]
HealthCheckNotConfigured(String),
#[error("container is unhealthy")]
Expand Down
6 changes: 6 additions & 0 deletions testcontainers/src/core/wait/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::{env::var, fmt::Debug, time::Duration};

pub use exit_strategy::ExitWaitStrategy;
pub use health_strategy::HealthWaitStrategy;
#[cfg(feature = "http_wait")]
pub use http_strategy::HttpWaitStrategy;
pub use log_strategy::LogWaitStrategy;

Expand All @@ -13,6 +14,7 @@ use crate::{
pub(crate) mod cmd_wait;
pub(crate) mod exit_strategy;
pub(crate) mod health_strategy;
#[cfg(feature = "http_wait")]
pub(crate) mod http_strategy;
pub(crate) mod log_strategy;

Expand All @@ -36,6 +38,7 @@ pub enum WaitFor {
/// Wait for the container's status to become `healthy`.
Healthcheck(HealthWaitStrategy),
/// Wait for a certain HTTP response.
#[cfg(feature = "http_wait")]
Http(HttpWaitStrategy),
/// Wait for the container to exit.
Exit(ExitWaitStrategy),
Expand Down Expand Up @@ -66,6 +69,7 @@ impl WaitFor {
}

/// Wait for a certain HTTP response.
#[cfg(feature = "http_wait")]
pub fn http(http_strategy: HttpWaitStrategy) -> WaitFor {
WaitFor::Http(http_strategy)
}
Expand Down Expand Up @@ -110,6 +114,7 @@ impl WaitFor {
}
}

#[cfg(feature = "http_wait")]
impl From<HttpWaitStrategy> for WaitFor {
fn from(value: HttpWaitStrategy) -> Self {
Self::Http(value)
Expand All @@ -130,6 +135,7 @@ impl WaitStrategy for WaitFor {
WaitFor::Healthcheck(strategy) => {
strategy.wait_until_ready(client, container).await?;
}
#[cfg(feature = "http_wait")]
WaitFor::Http(strategy) => {
strategy.wait_until_ready(client, container).await?;
}
Expand Down
10 changes: 7 additions & 3 deletions testcontainers/tests/async_runner.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use std::time::Duration;

use bollard::Docker;
use reqwest::StatusCode;
use testcontainers::{
core::{
logs::{consumer::logging_consumer::LoggingConsumer, LogFrame},
wait::{ExitWaitStrategy, HttpWaitStrategy, LogWaitStrategy},
CmdWaitFor, ExecCommand, IntoContainerPort, WaitFor,
wait::{ExitWaitStrategy, LogWaitStrategy},
CmdWaitFor, ExecCommand, WaitFor,
},
runners::AsyncRunner,
GenericImage, *,
Expand Down Expand Up @@ -144,8 +143,13 @@ async fn async_run_exec() -> anyhow::Result<()> {
Ok(())
}

#[cfg(feature = "http_wait")]
#[tokio::test]
async fn async_wait_for_http() -> anyhow::Result<()> {
use reqwest::StatusCode;
use testcontainers::core::wait::HttpWaitStrategy;
use testcontainers::core::IntoContainerPort;

let _ = pretty_env_logger::try_init();

let image = GenericImage::new("simple_web_server", "latest")
Expand Down
7 changes: 5 additions & 2 deletions testcontainers/tests/sync_runner.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#![cfg(feature = "blocking")]

use reqwest::StatusCode;
use testcontainers::{
core::{
logs::{consumer::logging_consumer::LoggingConsumer, LogFrame},
wait::{HttpWaitStrategy, LogWaitStrategy},
wait::LogWaitStrategy,
CmdWaitFor, ExecCommand, Host, IntoContainerPort, WaitFor,
},
runners::SyncRunner,
Expand Down Expand Up @@ -40,9 +39,13 @@ fn sync_can_run_hello_world() -> anyhow::Result<()> {
Ok(())
}

#[cfg(feature = "http_wait")]
#[test]
fn sync_wait_for_http() -> anyhow::Result<()> {
use crate::core::wait::HttpWaitStrategy;

let _ = pretty_env_logger::try_init();
use reqwest::StatusCode;

let image = GenericImage::new("simple_web_server", "latest")
.with_exposed_port(80.tcp())
Expand Down

0 comments on commit 38c7864

Please sign in to comment.