Skip to content

Commit

Permalink
add missing rust docs
Browse files Browse the repository at this point in the history
  • Loading branch information
milenkovicm committed Nov 15, 2023
1 parent 88846e6 commit 18d7b13
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Add dependency:
testcontainers-redpanda-rs = "0.1"
```

Usage example:
Create and run redpanda container:

```rust
use testcontainers::clients;
Expand All @@ -22,7 +22,7 @@ let docker = clients::Cli::default();
let container = Redpanda::latest();
let redpanda_node = docker.run(container);

// auto create topic is enabled by default,
// Auto create topic is enabled by default,
// use this if you need to create a topic with
// specific number of partitions.
redpanda_node.exec(Redpanda::cmd_create_topic("new_topic", 3));
Expand Down
25 changes: 16 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,15 @@ impl Redpanda {

#[allow(dead_code)]
impl Redpanda {
/// A command to create new topic with specified number of partitions
///
/// # Arguments
///
/// - `topic_name` name of the topic to be created
/// - `partitions` number fo partitions for given topic
pub fn cmd_create_topic(topic_name: &str, partitions: i32) -> ExecCommand {
log::debug!("cmd create topic [{}], with [{}] partition(s0", topic_name, partitions);
// not the best ready_condition
let ready_conditions = vec![
WaitFor::StdErrMessage {
message: String::from("Create topics"),
Expand All @@ -64,21 +71,26 @@ impl ImageArgs for RedpandaArgs {
Box::new(
vec![
"-c".into(),
"/usr/bin/rpk redpanda start --check=false --node-id 0 --set redpanda.auto_create_topics_enabled=true"
"/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;

fn name(&self) -> String {
// TODO: make container name configurable
"docker.redpanda.com/redpandadata/redpanda".into()
// there is a change in container name (and location)
// "docker.vectorized.io/vectorized/redpanda".into()
}

fn tag(&self) -> String {
Expand Down Expand Up @@ -109,12 +121,7 @@ impl Image for Redpanda {
vec![REDPANDA_PORT, SCHEMA_REGISTRY_PORT, ADMIN_PORT]
}

fn exec_after_start(&self, cs: ContainerState) -> Vec<ExecCommand> {
log::info!(
"setting extra configuration for test container ... port: {}",
cs.host_port_ipv4(REDPANDA_PORT)
);

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

0 comments on commit 18d7b13

Please sign in to comment.