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
This commit is contained in:
Jeena 2026-01-17 00:06:27 +00:00
parent 01bcda10d0
commit bde6181820
3 changed files with 31 additions and 46 deletions

View file

@ -1,20 +1,8 @@
use std::path::{Path, PathBuf};
use std::path::Path;
use tempfile::TempDir;
pub struct TestEnvironment {
pub temp_dir: TempDir,
pub config_path: PathBuf,
pub cert_path: PathBuf,
pub key_path: PathBuf,
pub content_path: PathBuf,
pub port: u16,
}
pub fn setup_test_environment() -> TestEnvironment {
pub fn setup_test_environment() -> TempDir {
let temp_dir = TempDir::new().unwrap();
let config_path = temp_dir.path().join("config.toml");
let cert_path = temp_dir.path().join("cert.pem");
let key_path = temp_dir.path().join("key.pem");
let content_path = temp_dir.path().join("content");
// Create content directory and file
@ -24,17 +12,7 @@ pub fn setup_test_environment() -> TestEnvironment {
// Generate test certificates
generate_test_certificates(temp_dir.path());
// Use a unique port based on process ID to avoid conflicts
let port = 1967 + (std::process::id() % 1000) as u16;
TestEnvironment {
temp_dir,
config_path,
cert_path,
key_path,
content_path,
port,
}
temp_dir
}
fn generate_test_certificates(temp_dir: &Path) {