use testcontainers::{core::WaitFor, Image};
pub const SOLR_PORT: u16 = 8983;
const NAME: &str = "solr";
const TAG: &str = "9.5.0-slim";
#[derive(Debug, Default, Clone)]
pub struct Solr {
_priv: (),
}
impl Image for Solr {
fn name(&self) -> &str {
NAME
}
fn tag(&self) -> &str {
TAG
}
fn ready_conditions(&self) -> Vec<WaitFor> {
vec![WaitFor::message_on_stdout("o.e.j.s.Server Started Server")]
}
}
#[cfg(test)]
mod tests {
use reqwest::{self, StatusCode};
use testcontainers::runners::SyncRunner;
use super::*;
#[test]
fn solr_ping() -> Result<(), Box<dyn std::error::Error + 'static>> {
let solr_image = Solr::default();
let container = solr_image.start()?;
let host_ip = container.get_host()?;
let host_port = container.get_host_port_ipv4(SOLR_PORT)?;
let url = format!("http://{host_ip}:{host_port}/solr/admin/cores?action=STATUS");
let res = reqwest::blocking::get(url).expect("valid HTTP response");
assert_eq!(res.status(), StatusCode::OK);
let json: serde_json::Value = res.json().expect("valid JSON body");
assert_eq!(json["responseHeader"]["status"], 0);
Ok(())
}
}