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
60
61
62
63
64
65
66
67
68
use std::collections::HashMap;

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

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

#[derive(Debug)]
pub struct OrientDb {
    env_vars: HashMap<String, String>,
}

impl Default for OrientDb {
    fn default() -> Self {
        let mut env_vars = HashMap::new();
        env_vars.insert("ORIENTDB_ROOT_PASSWORD".to_owned(), "root".to_owned());

        OrientDb { env_vars }
    }
}

impl Image for OrientDb {
    type Args = ();

    fn name(&self) -> String {
        NAME.to_owned()
    }

    fn tag(&self) -> String {
        TAG.to_owned()
    }

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

    fn env_vars(&self) -> Box<dyn Iterator<Item = (&String, &String)> + '_> {
        Box::new(self.env_vars.iter())
    }
}

#[cfg(test)]
mod tests {
    use testcontainers::clients;

    use crate::orientdb::OrientDb;

    #[test]
    fn orientdb_exists_database() {
        let docker = clients::Cli::default();
        let node = docker.run(OrientDb::default());

        let client =
            orientdb_client::OrientDB::connect(("127.0.0.1", node.get_host_port_ipv4(2424)))
                .unwrap();

        let exists = client
            .exist_database(
                "orientdb_exists_database",
                "root",
                "root",
                orientdb_client::DatabaseType::Memory,
            )
            .unwrap();

        assert!(!exists);
    }
}