added tests, use specific CI
This commit is contained in:
@@ -460,3 +460,122 @@ pub async fn repository_get_similar_items(
|
||||
.await
|
||||
.map_err(|e| format!("{:?}", e))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_repository_manager_creation() {
|
||||
let manager = RepositoryManager::new();
|
||||
// Should be able to create RepositoryManager without panicking
|
||||
assert_eq!(std::mem::size_of::<RepositoryManager>() > 0, true);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_repository_manager_wrapper_structure() {
|
||||
let manager = RepositoryManager::new();
|
||||
let wrapper = RepositoryManagerWrapper(manager);
|
||||
// Verify wrapper holds the manager
|
||||
assert_eq!(std::mem::size_of::<RepositoryManagerWrapper>() > 0, true);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_repository_manager_get_nonexistent() {
|
||||
let manager = RepositoryManager::new();
|
||||
// Getting a non-existent repository should return None
|
||||
let result = manager.get("nonexistent-handle");
|
||||
assert!(result.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_uuid_handle_generation() {
|
||||
let uuid = Uuid::new_v4();
|
||||
let handle = format!("{}", uuid);
|
||||
// UUID should convert to a non-empty string
|
||||
assert!(!handle.is_empty());
|
||||
assert!(handle.len() > 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_uuid_handles_are_unique() {
|
||||
let handle1 = format!("{}", Uuid::new_v4());
|
||||
let handle2 = format!("{}", Uuid::new_v4());
|
||||
// Two generated UUIDs should be different
|
||||
assert_ne!(handle1, handle2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_uuid_handle_format() {
|
||||
let uuid = Uuid::new_v4();
|
||||
let handle = format!("{}", uuid);
|
||||
// UUID should have standard format with hyphens
|
||||
let parts: Vec<&str> = handle.split('-').collect();
|
||||
assert_eq!(parts.len(), 5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_repository_manager_destroy_nonexistent() {
|
||||
let manager = RepositoryManager::new();
|
||||
// Destroying a non-existent repository should not panic
|
||||
manager.destroy("nonexistent-handle");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_repository_manager_is_send_sync() {
|
||||
// Verify RepositoryManager can be used in async contexts
|
||||
fn is_send_sync<T: Send + Sync>() {}
|
||||
is_send_sync::<RepositoryManager>();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_repository_manager_wrapper_is_send_sync() {
|
||||
// Verify RepositoryManagerWrapper is Send + Sync
|
||||
fn is_send_sync<T: Send + Sync>() {}
|
||||
is_send_sync::<RepositoryManagerWrapper>();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_multiple_manager_instances() {
|
||||
let manager1 = RepositoryManager::new();
|
||||
let manager2 = RepositoryManager::new();
|
||||
|
||||
// Multiple manager instances should be independent
|
||||
let handle1_nonexistent = manager1.get("test");
|
||||
let handle2_nonexistent = manager2.get("test");
|
||||
|
||||
assert!(handle1_nonexistent.is_none());
|
||||
assert!(handle2_nonexistent.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_handle_string_properties() {
|
||||
let uuid = Uuid::new_v4();
|
||||
let handle = format!("{}", uuid);
|
||||
|
||||
// Handle should be alphanumeric with hyphens
|
||||
for c in handle.chars() {
|
||||
assert!(c.is_alphanumeric() || c == '-');
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_repository_manager_concurrent_access() {
|
||||
let manager = Arc::new(RepositoryManager::new());
|
||||
let mut handles = vec![];
|
||||
|
||||
// Verify manager can be wrapped in Arc for concurrent access
|
||||
for _ in 0..3 {
|
||||
let mgr = Arc::clone(&manager);
|
||||
let handle = std::thread::spawn(move || {
|
||||
let result = mgr.get("test");
|
||||
assert!(result.is_none());
|
||||
});
|
||||
handles.push(handle);
|
||||
}
|
||||
|
||||
for h in handles {
|
||||
h.join().unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user