]> git.bitcoin.ninja Git - rapid-gossip-sync-server/commitdiff
Create test-aware db env vars.
authorArik Sosman <git@arik.io>
Tue, 15 Aug 2023 21:37:25 +0000 (14:37 -0700)
committerArik Sosman <git@arik.io>
Thu, 7 Sep 2023 04:12:52 +0000 (21:12 -0700)
src/config.rs

index 1de248220bd617057e4ccba5f55f34e2737cdd2f..0655aa7d48f9013f2d6171d06e4c83eeb1d99bfa 100644 (file)
@@ -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