diff options
| author | Alexander_Kabui <alexanderkabua@gmail.com> | 2026-10-03 20:49:38 +0300 |
|---|---|---|
| committer | Alexander_Kabui <alexanderkabua@gmail.com> | 2026-10-03 20:49:38 +0300 |
| commit | 08d6d33323d64c4dff6595adfac852257b27a2f9 (patch) | |
| tree | 5103c361930f69ea9a29dbbf1bb91fef122013e9 /src | |
| parent | fcde5ad4541832aca6c286ef4303c6d6a43f0a8d (diff) | |
| download | genenetwork4-08d6d33323d64c4dff6595adfac852257b27a2f9.tar.gz | |
Polish: import ordering, deterministic load_file tests.
Diffstat (limited to 'src')
| -rw-r--r-- | src/config.rs | 31 | ||||
| -rw-r--r-- | src/routes/groups.rs | 2 | ||||
| -rw-r--r-- | src/routes/species.rs | 2 |
3 files changed, 30 insertions, 5 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()); + } } diff --git a/src/routes/groups.rs b/src/routes/groups.rs index 7bf1710..9686302 100644 --- a/src/routes/groups.rs +++ b/src/routes/groups.rs @@ -2,9 +2,9 @@ //! InbredSet table and its strains. use axum::extract::{Extension, Path, Query}; -use tower_http::request_id::RequestId; use axum::http::StatusCode; use axum::Json; +use tower_http::request_id::RequestId; use crate::db; use crate::error::ApiError; diff --git a/src/routes/species.rs b/src/routes/species.rs index 682fac0..9731726 100644 --- a/src/routes/species.rs +++ b/src/routes/species.rs @@ -1,9 +1,9 @@ //! Species domain endpoints: read-only access to the Species table. use axum::extract::{Extension, Path}; -use tower_http::request_id::RequestId; use axum::http::StatusCode; use axum::Json; +use tower_http::request_id::RequestId; use crate::db; use crate::error::ApiError; |
