From: Arik Sosman Date: Tue, 15 Aug 2023 21:37:25 +0000 (-0700) Subject: Create test-aware db env vars. X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=8187e66963bd197dbc0443dae902578209ab512d;p=rapid-gossip-sync-server Create test-aware db env vars. --- diff --git a/src/config.rs b/src/config.rs index 1de2482..0655aa7 100644 --- a/src/config.rs +++ b/src/config.rs @@ -74,13 +74,19 @@ pub(crate) fn cache_path() -> String { 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