Get tests building and sort of passing
This commit is contained in:
35
src/state.rs
35
src/state.rs
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user