Skip to content

Commit

Permalink
update testcontainer to v 0.18
Browse files Browse the repository at this point in the history
  • Loading branch information
milenkovicm committed Jun 17, 2024
1 parent 72ed3dd commit 3003b76
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 37 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
63 changes: 28 additions & 35 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -20,20 +20,20 @@ pub struct Redpanda {

impl Redpanda {
/// creates test container for specified tag
pub fn for_tag(tag: String) -> RunnableImage<Self> {
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<Self> {
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<Self> {
pub fn default() -> ContainerRequest<Self> {
Self::latest()
}
/// creates test container with `latest` tag
pub fn latest() -> RunnableImage<Self> {
pub fn latest() -> ContainerRequest<Self> {
Self::for_tag("latest".into())
}
}
Expand Down Expand Up @@ -67,44 +67,37 @@ 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<dyn Iterator<Item = String>> {
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:
//
// ```
// docker run -ti --name=redpanda-1 --rm -p 9092:9092 -p 9644:9644 -p 8081:8081 docker.redpanda.com/redpandadata/redpanda redpanda start --mode dev-container --node-id 0 --set redpanda.auto_create_topics_enabled=true
// ```

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<Item = impl Into<std::borrow::Cow<'_, str>>> {
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<testcontainers::core::WaitFor> {
Expand All @@ -123,15 +116,15 @@ impl Image for Redpanda {
]
}

fn entrypoint(&self) -> Option<String> {
Some("sh".into())
fn entrypoint(&self) -> Option<&str> {
Some("sh")
}

fn expose_ports(&self) -> Vec<u16> {
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<Vec<ExecCommand>, TestcontainersError> {
Expand Down

0 comments on commit 3003b76

Please sign in to comment.