diff --git a/Cargo.toml b/Cargo.toml index 19c1d15..88fa503 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "testcontainers-redpanda-rs" -version = "0.3.1" +version = "0.4.0" edition = "2021" license = "MIT" description = "Unofficial redpanda test container" @@ -12,7 +12,7 @@ keywords = ["testcontainers", "testing", "kafka", "redpanda", "integration-testi [dependencies] log = "0.4" -testcontainers = { version = "0.17" } +testcontainers = { version = "0.18" } [dev-dependencies] env_logger = "0.11" diff --git a/README.md b/README.md index ee44d4a..97ca8eb 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ Unofficial testcontainer for [Redpanda](https://redpanda.com). Redpanda is a sim Note: +- version `0.4.x` supports `testcontainer` `0.18` - version `0.3.x` supports `testcontainer` `0.17` - version `0.2.x` supports `testcontainer` `0.16` - version `0.1.x` supports `testcontainer` `0.15` diff --git a/src/lib.rs b/src/lib.rs index 374889f..74b8666 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,8 +1,8 @@ #![doc = include_str!("../README.md")] use testcontainers::{ - core::{ContainerState, ExecCommand, WaitFor}, - Image, ImageArgs, RunnableImage, TestcontainersError, + core::{CmdWaitFor, ContainerPort, ContainerState, ExecCommand, WaitFor}, + ContainerRequest, Image, ImageExt, TestcontainersError, }; pub use testcontainers::runners::AsyncRunner; @@ -20,20 +20,20 @@ pub struct Redpanda { impl Redpanda { /// creates test container for specified tag - pub fn for_tag(tag: String) -> RunnableImage { - RunnableImage::from(Self { tag }) - .with_mapped_port((REDPANDA_PORT, REDPANDA_PORT)) - .with_mapped_port((SCHEMA_REGISTRY_PORT, SCHEMA_REGISTRY_PORT)) - .with_mapped_port((ADMIN_PORT, ADMIN_PORT)) + pub fn for_tag(tag: String) -> ContainerRequest { + ContainerRequest::from(Self { tag }) + .with_mapped_port(REDPANDA_PORT, ContainerPort::Tcp(REDPANDA_PORT)) + .with_mapped_port(SCHEMA_REGISTRY_PORT, ContainerPort::Tcp(SCHEMA_REGISTRY_PORT)) + .with_mapped_port(ADMIN_PORT, ContainerPort::Tcp(ADMIN_PORT)) } #[deprecated = "Use Self::latest()"] #[allow(clippy::should_implement_trait)] - pub fn default() -> RunnableImage { + pub fn default() -> ContainerRequest { Self::latest() } /// creates test container with `latest` tag - pub fn latest() -> RunnableImage { + pub fn latest() -> ContainerRequest { Self::for_tag("latest".into()) } } @@ -67,29 +67,13 @@ impl Redpanda { String::from("-p"), format!("{}", partitions), ]) - .with_cmd_ready_condition(WaitFor::Duration { + .with_cmd_ready_condition(CmdWaitFor::Duration { length: std::time::Duration::from_secs(1), }) .with_container_ready_conditions(container_ready_conditions) } } -#[derive(Debug, Default, Clone)] -pub struct RedpandaArgs {} - -impl ImageArgs for RedpandaArgs { - fn into_iterator(self) -> Box> { - Box::new( - vec![ - "-c".into(), - "/usr/bin/rpk redpanda start --mode dev-container --node-id 0 --set redpanda.auto_create_topics_enabled=true" - .into(), - ] - .into_iter(), - ) - } -} - // Test container should execute docker command similar to: // // ``` @@ -97,14 +81,23 @@ impl ImageArgs for RedpandaArgs { // ``` impl Image for Redpanda { - type Args = RedpandaArgs; + //type Args = RedpandaArgs; - fn name(&self) -> String { - "docker.redpanda.com/redpandadata/redpanda".into() + fn name(&self) -> &str { + "docker.redpanda.com/redpandadata/redpanda" + } + + fn cmd(&self) -> impl IntoIterator>> { + vec![ + "-c", + "/usr/bin/rpk redpanda start --mode dev-container --node-id 0 --set redpanda.auto_create_topics_enabled=true" + , + ] + .into_iter() } - fn tag(&self) -> String { - self.tag.to_owned() + fn tag(&self) -> &str { + self.tag.as_str() } fn ready_conditions(&self) -> Vec { @@ -123,15 +116,15 @@ impl Image for Redpanda { ] } - fn entrypoint(&self) -> Option { - Some("sh".into()) + fn entrypoint(&self) -> Option<&str> { + Some("sh") } - fn expose_ports(&self) -> Vec { + fn expose_ports(&self) -> &[ContainerPort] { // this is not needed as we map it explicitly // and testcontainer gets confused and re-map it // vec![REDPANDA_PORT, SCHEMA_REGISTRY_PORT, ADMIN_PORT] - vec![] + &[] } fn exec_after_start(&self, _: ContainerState) -> Result, TestcontainersError> {