use std::borrow::Cow;
use testcontainers::{
core::{ContainerPort, WaitFor},
Image,
};
const DEFAULT_IMAGE_NAME: &str = "gvenzl/oracle-free";
const DEFAULT_IMAGE_TAG: &str = "23-slim-faststart";
pub const FREE_PORT: ContainerPort = ContainerPort::Tcp(1521);
#[derive(Debug, Default, Clone)]
pub struct Oracle {
_priv: (),
}
impl Image for Oracle {
fn name(&self) -> &str {
DEFAULT_IMAGE_NAME
}
fn tag(&self) -> &str {
DEFAULT_IMAGE_TAG
}
fn ready_conditions(&self) -> Vec<WaitFor> {
vec![WaitFor::message_on_stdout("DATABASE IS READY TO USE!")]
}
fn env_vars(
&self,
) -> impl IntoIterator<Item = (impl Into<Cow<'_, str>>, impl Into<Cow<'_, str>>)> {
[
("ORACLE_PASSWORD", "testsys"),
("APP_USER", "test"),
("APP_USER_PASSWORD", "test"),
]
}
fn expose_ports(&self) -> &[ContainerPort] {
&[FREE_PORT]
}
}
#[cfg(test)]
mod tests {
use std::time::Duration;
use super::*;
use crate::testcontainers::{runners::SyncRunner, ImageExt};
#[test]
fn oracle_one_plus_one() -> Result<(), Box<dyn std::error::Error + 'static>> {
let oracle = Oracle::default()
.pull_image()?
.with_startup_timeout(Duration::from_secs(75));
let node = oracle.start()?;
let connection_string = format!(
"//{}:{}/FREEPDB1",
node.get_host()?,
node.get_host_port_ipv4(1521)?
);
let conn = oracle::Connection::connect("test", "test", connection_string)?;
let mut rows = conn.query("SELECT 1 + 1", &[])?;
let row = rows.next().unwrap()?;
let col: i32 = row.get(0)?;
assert_eq!(col, 2);
Ok(())
}
}