about summary refs log tree commit diff
path: root/src/config.rs
diff options
context:
space:
mode:
authorAlexander_Kabui <alexanderkabua@gmail.com>2026-10-03 20:49:38 +0300
committerAlexander_Kabui <alexanderkabua@gmail.com>2026-10-03 20:49:38 +0300
commit08d6d33323d64c4dff6595adfac852257b27a2f9 (patch)
tree5103c361930f69ea9a29dbbf1bb91fef122013e9 /src/config.rs
parentfcde5ad4541832aca6c286ef4303c6d6a43f0a8d (diff)
downloadgenenetwork4-08d6d33323d64c4dff6595adfac852257b27a2f9.tar.gz
Polish: import ordering, deterministic load_file tests.
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs31
1 files changed, 28 insertions, 3 deletions
diff --git a/src/config.rs b/src/config.rs
index eff8f22..496ff39 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -79,14 +79,39 @@ fn load_file(path: &str) -> HashMap<String, String> {
 mod tests {
     use super::*;
 
+    /// Defaults apply when nothing overrides them. Skips (rather than
+    /// flakes) if the surrounding environment happens to set any of the
+    /// knobs this test asserts on.
     #[test]
     fn defaults_apply_with_no_files_or_env() {
-        // Safe only because tests run without these set; guard anyway.
-        if std::env::var("SQL_URI").is_ok() || std::env::var("GN4_CONF").is_ok() {
-            return;
+        for key in ["SQL_URI", "GN4_CONF", "GN4_SECRETS", "GENENETWORK4_PORT"] {
+            if std::env::var(key).is_ok() {
+                eprintln!("skipping: {key} is set in the environment");
+                return;
+            }
         }
         let config = Config::load();
         assert!(config.sql_uri.contains("db_webqtl"));
         assert_eq!(config.port, 3000);
     }
+
+    #[test]
+    fn load_file_parses_key_value_lines() {
+        let path = std::env::temp_dir().join(format!("gn4-test-{}", std::process::id()));
+        std::fs::write(
+            &path,
+            "# comment\n\nSQL_URI = mysql://u:p@h/db\nGENENETWORK4_PORT=4000\n",
+        )
+        .unwrap();
+        let values = load_file(path.to_str().unwrap());
+        std::fs::remove_file(&path).unwrap();
+        assert_eq!(values["SQL_URI"], "mysql://u:p@h/db");
+        assert_eq!(values["GENENETWORK4_PORT"], "4000");
+        assert_eq!(values.len(), 2, "comments and blank lines are skipped");
+    }
+
+    #[test]
+    fn load_file_missing_file_yields_empty_map() {
+        assert!(load_file("/nonexistent/gn4.conf").is_empty());
+    }
 }