phase 5 qa and review pass

This commit is contained in:
2026-08-18 22:21:45 +01:00
parent bd7459e455
commit 42a697aa57
4 changed files with 295 additions and 168 deletions
+68
View File
@@ -265,3 +265,71 @@ pub enum IngestError {
pub type LookupMap = HashMap<String, HashMap<String, String>>;
pub type Result<T> = std::result::Result<T, IngestError>;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_config_load_missing_file_hard_error() {
let result = Config::load(Path::new("/nonexistent/path/config.json"));
assert!(result.is_err());
let err_msg = result.unwrap_err().to_string();
assert!(err_msg.contains("Failed to read config file"));
}
#[test]
fn test_config_load_invalid_json_error() {
let tmp = tempfile::NamedTempFile::new().unwrap();
std::fs::write(tmp.path(), "not valid json {{{").unwrap();
let result = Config::load(tmp.path());
assert!(result.is_err());
let err_msg = result.unwrap_err().to_string();
assert!(err_msg.contains("Failed to parse config file"));
}
#[test]
fn test_config_load_valid_file() {
let tmp = tempfile::NamedTempFile::new().unwrap();
let content = r#"{
"duckdb_path": "test.db",
"bind_address": "127.0.0.1:9090",
"data_source_url": "http://example.com",
"log_file_path": null,
"allowed_origins": ["https://example.com"]
}"#;
std::fs::write(tmp.path(), content).unwrap();
let config = Config::load(tmp.path()).unwrap();
assert_eq!(config.duckdb_path, "test.db");
assert_eq!(config.bind_address, "127.0.0.1:9090");
assert_eq!(config.data_source_url, "http://example.com");
assert!(config.log_file_path.is_none());
assert_eq!(config.allowed_origins, vec!["https://example.com"]);
}
#[test]
fn test_config_load_defaults_allowed_origins() {
let tmp = tempfile::NamedTempFile::new().unwrap();
let content = r#"{
"duckdb_path": "test.db",
"bind_address": "127.0.0.1:9090",
"data_source_url": "http://example.com"
}"#;
std::fs::write(tmp.path(), content).unwrap();
let config = Config::load(tmp.path()).unwrap();
assert!(config.allowed_origins.is_empty());
}
#[test]
fn test_config_default_values() {
let config = Config::default();
assert_eq!(config.duckdb_path, "hagfish.db");
assert_eq!(config.bind_address, "127.0.0.1:8090");
assert!(config.data_source_url.contains("statbank.hagstova.fo"));
assert!(config.log_file_path.is_some());
assert!(config.allowed_origins.is_empty());
}
}