Get tests building and sort of passing

This commit is contained in:
Cameron
2025-07-17 20:32:23 -04:00
parent 264195d3a2
commit 2ea36a4c9b
3 changed files with 79 additions and 57 deletions

View File

@@ -32,6 +32,7 @@ impl AppState {
gif_path,
}
}
}
impl Default for AppState {
@@ -45,3 +46,37 @@ impl Default for AppState {
)
}
}
#[cfg(test)]
impl AppState {
/// Creates an AppState instance for testing with temporary directories
pub fn test_state() -> Self {
use actix::Actor;
// Create a base temporary directory
let temp_dir = tempfile::tempdir().expect("Failed to create temp directory");
let base_path = temp_dir.path().to_path_buf();
// Create subdirectories for thumbnails, videos, and gifs
let thumbnail_path = create_test_subdir(&base_path, "thumbnails");
let video_path = create_test_subdir(&base_path, "videos");
let gif_path = create_test_subdir(&base_path, "gifs");
// Create the AppState with the temporary paths
AppState::new(
std::sync::Arc::new(crate::video::actors::StreamActor {}.start()),
base_path.to_string_lossy().to_string(),
thumbnail_path.to_string_lossy().to_string(),
video_path.to_string_lossy().to_string(),
gif_path.to_string_lossy().to_string(),
)
}
}
/// Helper function to create a subdirectory inside the base directory for testing
#[cfg(test)]
fn create_test_subdir(base_path: &std::path::Path, name: &str) -> std::path::PathBuf {
let dir_path = base_path.join(name);
std::fs::create_dir_all(&dir_path)
.expect(&format!("Failed to create {} directory", name));
dir_path
}