tiny steps towards unit testing for each resource

This commit is contained in:
Lennart
2025-06-27 14:33:25 +02:00
parent e2f5773e3c
commit 86ae31e94c
7 changed files with 85 additions and 8 deletions

View File

@@ -7,6 +7,9 @@ repository.workspace = true
license.workspace = true
publish = false
[features]
test = []
[dependencies]
tokio.workspace = true
rustical_store = { workspace = true }

View File

@@ -8,7 +8,7 @@ pub mod error;
pub mod principal_store;
pub mod subscription_store;
#[cfg(test)]
#[cfg(any(test, feature = "test"))]
pub mod tests;
#[derive(Debug, Clone, Serialize, sqlx::Type)]

View File

@@ -1,13 +1,42 @@
use crate::SqliteStore;
use crate::{
SqliteStore, addressbook_store::SqliteAddressbookStore, calendar_store::SqliteCalendarStore,
principal_store::SqlitePrincipalStore,
};
use rustical_store::{
AddressbookStore, CalendarStore, CollectionOperation, SubscriptionStore,
auth::AuthenticationProvider,
};
use sqlx::SqlitePool;
use std::sync::Arc;
use tokio::sync::mpsc::Receiver;
pub async fn create_test_db() -> Result<SqlitePool, sqlx::Error> {
let db = SqlitePool::connect("sqlite::memory:").await?;
sqlx::migrate!("./migrations").run(&db).await?;
Ok(db)
pub async fn get_test_stores() -> (
Arc<impl AddressbookStore>,
Arc<impl CalendarStore>,
Arc<impl SubscriptionStore>,
Arc<impl AuthenticationProvider>,
Receiver<CollectionOperation>,
) {
let db = SqlitePool::connect("sqlite::memory:").await.unwrap();
sqlx::migrate!("./migrations").run(&db).await.unwrap();
// let db = create_db_pool("sqlite::memory:", true).await.unwrap();
// Channel to watch for changes (for DAV Push)
let (send, recv) = tokio::sync::mpsc::channel(1000);
let addressbook_store = Arc::new(SqliteAddressbookStore::new(db.clone(), send.clone()));
let cal_store = Arc::new(SqliteCalendarStore::new(db.clone(), send));
let subscription_store = Arc::new(SqliteStore::new(db.clone()));
let principal_store = Arc::new(SqlitePrincipalStore::new(db.clone()));
(
addressbook_store,
cal_store,
subscription_store,
principal_store,
recv,
)
}
#[tokio::test]
async fn test_create_store() {
SqliteStore::new(create_test_db().await.unwrap());
get_test_stores().await;
}