testcontainers_modules/rqlite/
mod.rs1use testcontainers::{
2 core::{wait::HttpWaitStrategy, ContainerPort, WaitFor},
3 Image,
4};
5
6pub const RQLITE_PORT: ContainerPort = ContainerPort::Tcp(4001);
11
12const NAME: &str = "rqlite/rqlite";
13const TAG: &str = "8.36.3";
14
15#[derive(Debug, Default, Clone)]
32pub struct RQLite {
33 _priv: (),
37}
38
39impl Image for RQLite {
40 fn name(&self) -> &str {
41 NAME
42 }
43
44 fn tag(&self) -> &str {
45 TAG
46 }
47
48 fn ready_conditions(&self) -> Vec<WaitFor> {
49 vec![
50 WaitFor::http(HttpWaitStrategy::new("/status").with_expected_status_code(200_u16)),
51 WaitFor::message_on_stderr("is now Leader"),
52 ]
53 }
54
55 fn expose_ports(&self) -> &[ContainerPort] {
56 &[RQLITE_PORT]
57 }
58}
59
60#[cfg(test)]
61mod tests {
62 use testcontainers::runners::AsyncRunner;
63
64 use crate::rqlite::RQLite;
65
66 #[tokio::test]
67 async fn rqlite_db() -> Result<(), Box<dyn std::error::Error + 'static>> {
68 let _ = pretty_env_logger::try_init();
69 let node = RQLite::default().start().await?;
70 let host_ip = node.get_host().await?;
71 let host_port = node.get_host_port_ipv4(4001).await?;
72
73 let client = rqlite_rs::RqliteClientBuilder::new()
74 .known_host(format!("{host_ip}:{host_port}"))
75 .build()?;
76
77 let query = rqlite_rs::query!("SELECT 1+1")?;
78 let rows = client.fetch(query).await?;
79 assert_eq!(rows.len(), 1);
80
81 let first_row = &rows[0];
82 let first_column: i32 = first_row.get("1+1")?;
83 assert_eq!(first_column, 2);
84
85 Ok(())
86 }
87}