-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathtests.rs
More file actions
127 lines (115 loc) · 3.74 KB
/
Copy pathtests.rs
File metadata and controls
127 lines (115 loc) · 3.74 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
use std::{collections::BTreeMap, ops::Deref};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use crate::{
builder::pod::container::ContainerBuilder,
database_connections::{
TemplatingMechanism,
databases::{
postgresql::{POSTGRES_JDBC_DRIVER_CLASS, PostgresqlConnection},
redis::RedisConnection,
},
drivers::{
celery::{CeleryDatabaseConnection, GenericCeleryDatabaseConnection},
jdbc::{GenericJdbcDatabaseConnection, JdbcDatabaseConnection},
},
},
};
#[derive(Clone, Debug, Deserialize, JsonSchema, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
enum DummyJdbcConnection {
Postgresql(PostgresqlConnection),
#[allow(unused)]
Generic(GenericJdbcDatabaseConnection),
}
impl Deref for DummyJdbcConnection {
type Target = dyn JdbcDatabaseConnection;
fn deref(&self) -> &Self::Target {
match self {
Self::Postgresql(p) => p,
Self::Generic(g) => g,
}
}
}
#[derive(Clone, Debug, Deserialize, JsonSchema, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
enum DummyCeleryConnection {
Postgresql(PostgresqlConnection),
Redis(RedisConnection),
#[allow(unused)]
Generic(GenericCeleryDatabaseConnection),
}
impl Deref for DummyCeleryConnection {
type Target = dyn CeleryDatabaseConnection;
fn deref(&self) -> &Self::Target {
match self {
Self::Postgresql(p) => p,
Self::Redis(r) => r,
Self::Generic(g) => g,
}
}
}
#[test]
fn test_dummy_jdbc_database_usage() {
// Set up test data
let dummy_jdbc_connection = DummyJdbcConnection::Postgresql(PostgresqlConnection {
host: "my-database".parse().expect("static host is always valid"),
port: 1234,
database: "my_schema".to_owned(),
credentials_secret_name: "my-credentials".to_owned(),
parameters: BTreeMap::new(),
});
// Apply actual config
let jdbc_connection_details = dummy_jdbc_connection
.jdbc_connection_details("persistence")
.unwrap();
let mut container_builder = ContainerBuilder::new("my-container").unwrap();
jdbc_connection_details.add_to_container(&mut container_builder);
let container = container_builder.build();
assert_eq!(jdbc_connection_details.driver, POSTGRES_JDBC_DRIVER_CLASS);
assert_eq!(
jdbc_connection_details.connection_url.to_string(),
"jdbc:postgresql://my-database:1234/my_schema"
);
assert_eq!(
container
.env
.unwrap()
.iter()
.map(|env| &env.name)
.collect::<Vec<_>>(),
vec![
"PERSISTENCE_DATABASE_USERNAME",
"PERSISTENCE_DATABASE_PASSWORD"
]
);
}
#[test]
fn test_dummy_celery_database_usage() {
// Set up test data
let dummy_celery_connection = DummyCeleryConnection::Generic(GenericCeleryDatabaseConnection {
connection_url_secret_name: "my-celery-db".to_owned(),
});
// Apply actual config
let celery_connection_details = dummy_celery_connection
.celery_connection_details_with_templating(
"worker_queue",
&TemplatingMechanism::BashEnvSubstitution,
);
let mut container_builder = ContainerBuilder::new("my-container").unwrap();
celery_connection_details.add_to_container(&mut container_builder);
let container = container_builder.build();
assert_eq!(
celery_connection_details.url_template,
"${WORKER_QUEUE_DATABASE_URL}"
);
assert_eq!(
container
.env
.unwrap()
.iter()
.map(|env| &env.name)
.collect::<Vec<_>>(),
vec!["WORKER_QUEUE_DATABASE_URL"]
);
}