pub(crate) fn db_connection_config() -> Config {
let mut config = Config::new();
- let host = env::var("RAPID_GOSSIP_SYNC_SERVER_DB_HOST").unwrap_or("localhost".to_string());
- let user = env::var("RAPID_GOSSIP_SYNC_SERVER_DB_USER").unwrap_or("alice".to_string());
- let db = env::var("RAPID_GOSSIP_SYNC_SERVER_DB_NAME").unwrap_or("ln_graph_sync".to_string());
+ let env_name_prefix = if cfg!(test) {
+ "RAPID_GOSSIP_TEST_DB"
+ } else {
+ "RAPID_GOSSIP_SYNC_SERVER_DB"
+ };
+
+ let host = env::var(format!("{}{}", env_name_prefix, "_HOST")).unwrap_or("localhost".to_string());
+ let user = env::var(format!("{}{}", env_name_prefix, "_USER")).unwrap_or("alice".to_string());
+ let db = env::var(format!("{}{}", env_name_prefix, "_NAME")).unwrap_or("ln_graph_sync".to_string());
config.host(&host);
config.user(&user);
config.dbname(&db);
- if let Ok(password) = env::var("RAPID_GOSSIP_SYNC_SERVER_DB_PASSWORD") {
+ if let Ok(password) = env::var(format!("{}{}", env_name_prefix, "_PASSWORD")) {
config.password(&password);
}
config