use std::collections::HashMap; use std::path::PathBuf; use std::sync::Arc; use pinakes_core::media_type::{BuiltinMediaType, MediaType}; use pinakes_core::model::{ContentHash, MediaId, MediaItem, StorageMode}; use pinakes_core::storage::{DynStorageBackend, StorageBackend, sqlite::SqliteBackend}; use tempfile::TempDir; use uuid::Uuid; pub async fn setup() -> Arc { let backend = SqliteBackend::in_memory().expect("in-memory SQLite"); backend.run_migrations().await.expect("migrations"); Arc::new(backend) } pub async fn setup_test_storage() -> (DynStorageBackend, TempDir) { let temp_dir = TempDir::new().unwrap(); let db_path = temp_dir.path().join(format!("test_{}.db", Uuid::now_v7())); let storage = SqliteBackend::new(&db_path).unwrap(); storage.run_migrations().await.unwrap(); (Arc::new(storage), temp_dir) } pub fn make_test_media(hash: &str) -> MediaItem { let now = chrono::Utc::now(); MediaItem { id: MediaId::new(), path: format!("/tmp/test_{hash}.mp4").into(), file_name: format!("test_{hash}.mp4"), media_type: MediaType::Builtin(BuiltinMediaType::Mp4), content_hash: ContentHash::new(hash.to_string()), file_size: 1000, title: Some(format!("Test {hash}")), artist: Some("Test Artist".to_string()), album: None, genre: None, year: Some(2024), duration_secs: Some(120.0), description: None, thumbnail_path: None, custom_fields: HashMap::new(), file_mtime: None, date_taken: None, latitude: None, longitude: None, camera_make: None, camera_model: None, rating: None, perceptual_hash: None, storage_mode: StorageMode::External, original_filename: None, uploaded_at: None, storage_key: None, created_at: now, updated_at: now, deleted_at: None, } } pub fn create_test_media_item(path: PathBuf, hash: &str) -> MediaItem { let now = chrono::Utc::now(); MediaItem { id: MediaId(Uuid::now_v7()), path, file_name: "test.mp3".to_string(), media_type: MediaType::Builtin(BuiltinMediaType::Mp3), content_hash: ContentHash(hash.to_string()), file_size: 1000, title: None, artist: None, album: None, genre: None, year: None, duration_secs: None, description: None, thumbnail_path: None, custom_fields: HashMap::new(), file_mtime: None, date_taken: None, latitude: None, longitude: None, camera_make: None, camera_model: None, rating: None, perceptual_hash: None, storage_mode: StorageMode::External, original_filename: None, uploaded_at: None, storage_key: None, created_at: now, updated_at: now, deleted_at: None, } }