use std::collections::HashSet; use server18004::state::AppState; /// Creates a test AppState with the given allowed domains. /// Uses a temp directory for the domains file so tests don't interfere. pub fn test_state(domains: &[&str]) -> AppState { let domain_set: HashSet = domains.iter().map(|s| s.to_string()).collect(); // Use a temp file for domain persistence during tests let tmp_dir = tempfile::tempdir().expect("Failed to create temp dir"); let domains_path = tmp_dir .path() .join("domains.conf") .to_str() .unwrap() .to_string(); // We need to leak the TempDir so it doesn't get cleaned up during the test // (the test functions are short-lived, this is fine for testing) std::mem::forget(tmp_dir); AppState::new(domain_set, domains_path, "test-default.com".to_string()) }