From 65a060fe3fc6e31f2eaae486fe8292eb6be44fc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Milenkovi=C4=87?= Date: Mon, 27 May 2024 20:26:17 +0100 Subject: [PATCH] update testcontainer to 0.17 --- Cargo.toml | 4 ++-- README.md | 6 +++--- src/lib.rs | 10 +++++----- tests/verification.rs | 30 +++++++++++++++++++++--------- 4 files changed, 31 insertions(+), 19 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1d27c40..358d393 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "testcontainers-redpanda-rs" -version = "0.2.1" +version = "0.3.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.16" } +testcontainers = { version = "0.17" } [dev-dependencies] env_logger = "0.11" diff --git a/README.md b/README.md index 8dd48d2..e110154 100644 --- a/README.md +++ b/README.md @@ -27,12 +27,12 @@ use testcontainers_redpanda_rs::*; async fn main() { let container = Redpanda::latest(); - let server_node = container.start().await; - let bootstrap_servers = format!("localhost:{}", server_node.get_host_port_ipv4(REDPANDA_PORT).await); + let server_node = container.start().await.unwrap(); + let bootstrap_servers = format!("localhost:{}", server_node.get_host_port_ipv4(REDPANDA_PORT).await.unwrap()); // if topic has only one partition this part is optional // it will be automatically created when client connects let test_topic_name = "test_topic"; - server_node.exec(Redpanda::cmd_create_topic(test_topic_name, 3)).await; + server_node.exec(Redpanda::cmd_create_topic(test_topic_name, 3)).await.unwrap(); println!("Redpanda server: {}", bootstrap_servers); } diff --git a/src/lib.rs b/src/lib.rs index 2278f2f..374889f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,7 +2,7 @@ use testcontainers::{ core::{ContainerState, ExecCommand, WaitFor}, - Image, ImageArgs, RunnableImage, + Image, ImageArgs, RunnableImage, TestcontainersError, }; pub use testcontainers::runners::AsyncRunner; @@ -51,7 +51,7 @@ impl Redpanda { // not the best ready_condition let container_ready_conditions = vec![ WaitFor::StdErrMessage { - message: String::from("Create topics"), + message: "Create topics".into(), }, WaitFor::Duration { length: std::time::Duration::from_secs(1), @@ -114,7 +114,7 @@ impl Image for Redpanda { // message: String::from("Successfully started Redpanda!"), // as at that point cluster will be initialized and client will retrieve // right cluster id. - message: String::from("Initialized cluster_id to "), + message: "Initialized cluster_id to ".into(), }, // No need to wait for cluster to settle down if we get `Initialized cluster_id to` message // WaitFor::Duration { @@ -134,8 +134,8 @@ impl Image for Redpanda { vec![] } - fn exec_after_start(&self, _: ContainerState) -> Vec { - vec![] + fn exec_after_start(&self, _: ContainerState) -> Result, TestcontainersError> { + Ok(vec![]) } } diff --git a/tests/verification.rs b/tests/verification.rs index 116787c..086a224 100644 --- a/tests/verification.rs +++ b/tests/verification.rs @@ -9,8 +9,11 @@ mod test { async fn should_start_redpanda_server_send_messages() { let container = Redpanda::latest(); - let instance = container.start().await; - let bootstrap_servers = format!("localhost:{}", instance.get_host_port_ipv4(REDPANDA_PORT).await); + let instance = container.start().await.unwrap(); + let bootstrap_servers = format!( + "localhost:{}", + instance.get_host_port_ipv4(REDPANDA_PORT).await.unwrap() + ); log::info!("bootstrap servers: {}", bootstrap_servers); let test_topic_name = random_topic_name(); @@ -23,14 +26,20 @@ mod test { async fn should_start_redpanda_server_crate_topic_send_messages_to_partition() { let container = Redpanda::latest(); - let instance = container.start().await; - let bootstrap_servers = format!("localhost:{}", instance.get_host_port_ipv4(REDPANDA_PORT).await); + let instance = container.start().await.unwrap(); + let bootstrap_servers = format!( + "localhost:{}", + instance.get_host_port_ipv4(REDPANDA_PORT).await.unwrap() + ); // if topic has only one partition this part is optional // it will be automatically created when client connects let test_topic_name = &random_topic_name(); log::info!("creating topic: [{}] ...", test_topic_name); - instance.exec(Redpanda::cmd_create_topic(test_topic_name, 3)).await; + instance + .exec(Redpanda::cmd_create_topic(test_topic_name, 3)) + .await + .unwrap(); log::info!("bootstrap servers: {}", bootstrap_servers); @@ -52,8 +61,11 @@ mod test { async fn should_expose_admin_api() { let container = Redpanda::latest(); - let instance = container.start().await; - let address_admin_api = format!("http://localhost:{}/v1", instance.get_host_port_ipv4(ADMIN_PORT).await); + let instance = container.start().await.unwrap(); + let address_admin_api = format!( + "http://localhost:{}/v1", + instance.get_host_port_ipv4(ADMIN_PORT).await.unwrap() + ); let response = reqwest::get(address_admin_api).await.expect("admin http response"); @@ -65,10 +77,10 @@ mod test { async fn should_expose_schema_registry_api() { let container = Redpanda::latest(); - let instance = container.start().await; + let instance = container.start().await.unwrap(); let address_schema_registry = format!( "http://localhost:{}/v1", - instance.get_host_port_ipv4(SCHEMA_REGISTRY_PORT).await + instance.get_host_port_ipv4(SCHEMA_REGISTRY_PORT).await.unwrap() ); let response = reqwest::get(address_schema_registry)