test(config): add config loading tests

This commit is contained in:
objz committed 2026-02-22 15:15:18 +01:00
1 parent 73465a8b12
commit 973602fcfb
1 file changed
+61
+61
View File
@@ -95,3 +95,64 @@ pub static SETTINGS: Lazy<Config> = 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());
}
}