contain_rs_postgres/
lib.rs

1use contain_rs::*;
2
3#[derive(ContainerImpl)]
4#[container(
5    image = "docker.io/library/postgres",
6    health_check_command = "pg_isready"
7)]
8pub struct Postgres {
9    #[contain_rs(env_var = "POSTGRES_DB")]
10    db: Option<String>,
11    #[contain_rs(env_var = "POSTGRES_USER")]
12    user: Option<String>,
13    #[contain_rs(env_var = "POSTGRES_PASSWORD")]
14    password: String,
15}
16
17impl Default for Postgres {
18    fn default() -> Self {
19        Self {
20            db: None,
21            user: None,
22            password: "default_pw".to_string(),
23        }
24    }
25}
26
27impl Postgres {
28    pub fn with_password(mut self, password: &str) -> Self {
29        self.password = password.to_string();
30        self
31    }
32
33    pub fn with_user(mut self, user: &str) -> Self {
34        self.user = Some(user.to_string());
35        self
36    }
37
38    pub fn with_db(mut self, db: &str) -> Self {
39        self.db = Some(db.to_string());
40        self
41    }
42}
43
44#[cfg(test)]
45mod test {
46    use contain_rs::{Client, Handle, Podman};
47
48    use crate::Postgres;
49
50    #[test]
51    fn test_run() {
52        let client = Podman::new();
53        let container = client.create(Postgres::default());
54
55        container.run_and_wait().unwrap();
56    }
57}