From 973602fcfbb91237e280363c4540148867d59dba Mon Sep 17 00:00:00 2001 From: objz Date: Sun, 22 Feb 2026 15:15:18 +0100 Subject: [PATCH] test(config): add config loading tests --- src/config/mod.rs | 61 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/src/config/mod.rs b/src/config/mod.rs index 2a50dd0..ad89082 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -95,3 +95,64 @@ pub static SETTINGS: Lazy = Lazy::new(|| { } } }); + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn load_config_from_valid_toml() { + let tmp = tempfile::tempdir().unwrap(); + let path = tmp.path().join("config.toml"); + std::fs::write( + &path, + r#" +[general] +debug = true + +[defaults] +memory_max = "4G" +"#, + ) + .unwrap(); + let config = load_config(&path).unwrap(); + assert!(config.general.debug); + assert_eq!(config.defaults.memory_max, "4G"); + assert_eq!(config.defaults.memory_min, "512M"); + } + + #[test] + fn load_config_from_empty_file() { + let tmp = tempfile::tempdir().unwrap(); + let path = tmp.path().join("config.toml"); + std::fs::write(&path, "").unwrap(); + let config = load_config(&path).unwrap(); + assert!(!config.general.debug); + assert_eq!(config.defaults.memory_max, "2G"); + } + + #[test] + fn load_config_missing_file_uses_defaults() { + let tmp = tempfile::tempdir().unwrap(); + let path = tmp.path().join("nonexistent.toml"); + let config = load_config(&path).unwrap(); + assert!(!config.general.debug); + } + + #[test] + fn load_config_partial_sections() { + let tmp = tempfile::tempdir().unwrap(); + let path = tmp.path().join("config.toml"); + std::fs::write( + &path, + r#" +[paths] +instances_dir = "/custom/path" +"#, + ) + .unwrap(); + let config = load_config(&path).unwrap(); + assert_eq!(config.paths.instances_dir, "/custom/path"); + assert!(config.paths.java_path.is_none()); + } +}