1use std::collections::HashMap;
2use tc_core::{Container, Docker, Image, WaitForMessage};
3
4#[derive(Debug)]
5pub struct Postgres {
6 arguments: PostgresArgs,
7}
8
9#[derive(Default, Debug, Clone)]
10pub struct PostgresArgs {}
11
12impl IntoIterator for PostgresArgs {
13 type Item = String;
14 type IntoIter = ::std::vec::IntoIter<String>;
15
16 fn into_iter(self) -> Self::IntoIter {
17 vec![].into_iter()
18 }
19}
20
21impl Default for Postgres {
22 fn default() -> Self {
23 Self {
24 arguments: PostgresArgs::default(),
25 }
26 }
27}
28
29impl Image for Postgres {
30 type Args = PostgresArgs;
31 type EnvVars = HashMap<String, String>;
32
33 fn descriptor(&self) -> String {
34 "postgres:11-alpine".to_string()
35 }
36
37 fn wait_until_ready<D: Docker>(&self, container: &Container<D, Self>) {
38 container
39 .logs()
40 .stderr
41 .wait_for_message("database system is ready to accept connections")
42 .unwrap();
43 }
44
45 fn args(&self) -> Self::Args {
46 self.arguments.clone()
47 }
48
49 fn env_vars(&self) -> Self::EnvVars {
50 HashMap::new()
51 }
52
53 fn with_args(self, arguments: Self::Args) -> Self {
54 Self { arguments, ..self }
55 }
56}