pollux/tests/common.rs
Jeena bde6181820 Simplify test environment setup to return TempDir directly
- Remove TestEnvironment struct and return TempDir from setup function
- Update tests to compute paths from temp_dir.path() on-demand
- Eliminate unused field warnings and reduce code complexity
- Maintain all test functionality with cleaner design
2026-01-17 00:06:27 +00:00

37 lines
No EOL
1 KiB
Rust

use std::path::Path;
use tempfile::TempDir;
pub fn setup_test_environment() -> TempDir {
let temp_dir = TempDir::new().unwrap();
let content_path = temp_dir.path().join("content");
// Create content directory and file
std::fs::create_dir(&content_path).unwrap();
std::fs::write(content_path.join("test.gmi"), "# Test Gemini content\n").unwrap();
// Generate test certificates
generate_test_certificates(temp_dir.path());
temp_dir
}
fn generate_test_certificates(temp_dir: &Path) {
use std::process::Command;
let cert_path = temp_dir.join("cert.pem");
let key_path = temp_dir.join("key.pem");
let status = Command::new("openssl")
.args(&[
"req", "-x509", "-newkey", "rsa:2048",
"-keyout", &key_path.to_string_lossy(),
"-out", &cert_path.to_string_lossy(),
"-days", "1",
"-nodes",
"-subj", "/CN=localhost"
])
.status()
.unwrap();
assert!(status.success(), "Failed to generate test certificates");
}