Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I4c4815ad145650a07f108614034d2e996a6a6964
142 lines
4.1 KiB
Rust
142 lines
4.1 KiB
Rust
// Common test utilities shared across integration tests
|
|
// Functions may appear unused in individual test binaries - they're used across
|
|
// the test suite
|
|
#![allow(dead_code)]
|
|
|
|
use std::{collections::HashMap, path::PathBuf, sync::Arc};
|
|
|
|
use pinakes_core::{
|
|
media_type::{BuiltinMediaType, MediaType},
|
|
model::{ContentHash, MediaId, MediaItem, StorageMode},
|
|
storage::{DynStorageBackend, StorageBackend, sqlite::SqliteBackend},
|
|
};
|
|
use tempfile::TempDir;
|
|
use uuid::Uuid;
|
|
|
|
pub async fn setup() -> Arc<SqliteBackend> {
|
|
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,
|
|
links_extracted_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,
|
|
links_extracted_at: None,
|
|
}
|
|
}
|
|
|
|
/// Create a test markdown media item with a given ID
|
|
pub fn make_test_markdown_item(id: MediaId) -> MediaItem {
|
|
let now = chrono::Utc::now();
|
|
MediaItem {
|
|
id,
|
|
path: format!("/tmp/test_{}.md", id.0).into(),
|
|
file_name: format!("test_{}.md", id.0),
|
|
media_type: MediaType::Builtin(BuiltinMediaType::Markdown),
|
|
content_hash: ContentHash::new(format!("hash_{}", id.0)),
|
|
file_size: 1024,
|
|
title: Some("Test Note".to_string()),
|
|
artist: None,
|
|
album: None,
|
|
genre: None,
|
|
year: None,
|
|
duration_secs: None,
|
|
description: Some("Test markdown note".to_string()),
|
|
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,
|
|
links_extracted_at: None,
|
|
}
|
|
}
|