Skip to content

Commit

Permalink
update testcontainer to 0.17
Browse files Browse the repository at this point in the history
  • Loading branch information
milenkovicm committed May 27, 2024
1 parent b73e349 commit 65a060f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 19 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.2.1"
version = "0.3.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.16" }
testcontainers = { version = "0.17" }

[dev-dependencies]
env_logger = "0.11"
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
10 changes: 5 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use testcontainers::{
core::{ContainerState, ExecCommand, WaitFor},
Image, ImageArgs, RunnableImage,
Image, ImageArgs, RunnableImage, TestcontainersError,
};

pub use testcontainers::runners::AsyncRunner;
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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 {
Expand All @@ -134,8 +134,8 @@ impl Image for Redpanda {
vec![]
}

fn exec_after_start(&self, _: ContainerState) -> Vec<ExecCommand> {
vec![]
fn exec_after_start(&self, _: ContainerState) -> Result<Vec<ExecCommand>, TestcontainersError> {
Ok(vec![])
}
}

Expand Down
30 changes: 21 additions & 9 deletions tests/verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);

Expand All @@ -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");

Expand All @@ -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)
Expand Down

0 comments on commit 65a060f

Please sign in to comment.