1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use std::borrow::Cow;

use testcontainers::{core::WaitFor, Image};

const NAME: &str = "orientdb";
const TAG: &str = "3.2.19";

#[derive(Debug, Default)]
pub struct OrientDb {
    _priv: (),
}

impl Image for OrientDb {
    fn name(&self) -> &str {
        NAME
    }

    fn tag(&self) -> &str {
        TAG
    }

    fn ready_conditions(&self) -> Vec<WaitFor> {
        vec![WaitFor::message_on_stderr("OrientDB Studio available at")]
    }

    fn env_vars(
        &self,
    ) -> impl IntoIterator<Item = (impl Into<Cow<'_, str>>, impl Into<Cow<'_, str>>)> {
        [("ORIENTDB_ROOT_PASSWORD", "root")]
    }
}

#[cfg(test)]
mod tests {
    use reqwest::StatusCode;
    use retry::{delay::Fixed, retry};

    use crate::{orientdb::OrientDb, testcontainers::runners::SyncRunner};

    #[test]
    fn orientdb_exists_database() {
        let _ = pretty_env_logger::try_init();
        let node = OrientDb::default().start().unwrap();
        let client = reqwest::blocking::Client::new();

        let response = retry(Fixed::from_millis(500).take(5), || {
            client
                .get(format!(
                    "http://{}:{}/listDatabases",
                    node.get_host().unwrap(),
                    node.get_host_port_ipv4(2480).unwrap()
                ))
                .header("Accept-Encoding", "gzip,deflate")
                .send()
        });

        assert_eq!(response.unwrap().status(), StatusCode::OK);
    }
}