first commit
This commit is contained in:
23
tests/common/mod.rs
Normal file
23
tests/common/mod.rs
Normal file
@@ -0,0 +1,23 @@
|
||||
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<String> = 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())
|
||||
}
|
||||
3
tests/common/test_health.http
Normal file
3
tests/common/test_health.http
Normal file
@@ -0,0 +1,3 @@
|
||||
GET http://127.0.0.1:4083/domains HTTP/1.1
|
||||
content-type: application/json
|
||||
|
||||
Reference in New Issue
Block a user