testcontainers_modules/orientdb/mod.rs
1use std::borrow::Cow;
2
3use testcontainers::{core::WaitFor, Image};
4
5const NAME: &str = "orientdb";
6const TAG: &str = "3.2.19";
7
8/// Module to work with [`OrientDB`] inside of tests.
9///
10/// Starts an instance of OrientDB based on the official [`OrientDB docker image`].
11///
12/// OrientDB is a multi-model database, supporting graph, document, object, and key-value models.
13/// This module provides a local OrientDB instance for testing purposes.
14/// The container exposes port `2424` for binary connections and port `2480` for HTTP connections by default.
15///
16/// The default root password is set to `"root"`.
17///
18/// # Example
19/// ```
20/// use testcontainers_modules::{orientdb::OrientDb, testcontainers::runners::SyncRunner};
21///
22/// let orientdb_instance = OrientDb::default().start().unwrap();
23/// let host = orientdb_instance.get_host().unwrap();
24/// let http_port = orientdb_instance.get_host_port_ipv4(2480).unwrap();
25/// let binary_port = orientdb_instance.get_host_port_ipv4(2424).unwrap();
26///
27/// // Use the HTTP endpoint at http://{host}:{http_port}
28/// // Use the binary endpoint at {host}:{binary_port}
29/// ```
30///
31/// [`OrientDB`]: https://orientdb.org/
32/// [`OrientDB docker image`]: https://hub.docker.com/_/orientdb
33#[derive(Debug, Default, Clone)]
34pub struct OrientDb {
35 /// (remove if there is another variable)
36 /// Field is included to prevent this struct to be a unit struct.
37 /// This allows extending functionality (and thus further variables) without breaking changes
38 _priv: (),
39}
40
41impl Image for OrientDb {
42 fn name(&self) -> &str {
43 NAME
44 }
45
46 fn tag(&self) -> &str {
47 TAG
48 }
49
50 fn ready_conditions(&self) -> Vec<WaitFor> {
51 vec![WaitFor::message_on_stderr("OrientDB Studio available at")]
52 }
53
54 fn env_vars(
55 &self,
56 ) -> impl IntoIterator<Item = (impl Into<Cow<'_, str>>, impl Into<Cow<'_, str>>)> {
57 [("ORIENTDB_ROOT_PASSWORD", "root")]
58 }
59}
60
61#[cfg(test)]
62mod tests {
63 use reqwest::StatusCode;
64 use retry::{delay::Fixed, retry};
65
66 use crate::{orientdb::OrientDb, testcontainers::runners::SyncRunner};
67
68 #[test]
69 fn orientdb_exists_database() {
70 let _ = pretty_env_logger::try_init();
71 let node = OrientDb::default().start().unwrap();
72 let client = reqwest::blocking::Client::new();
73
74 let response = retry(Fixed::from_millis(500).take(5), || {
75 client
76 .get(format!(
77 "http://{}:{}/listDatabases",
78 node.get_host().unwrap(),
79 node.get_host_port_ipv4(2480).unwrap()
80 ))
81 .header("Accept-Encoding", "gzip,deflate")
82 .send()
83 });
84
85 assert_eq!(response.unwrap().status(), StatusCode::OK);
86 }
87}