mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 22:52:22 +00:00
tiny steps towards unit testing for each resource
This commit is contained in:
@@ -7,6 +7,9 @@ repository.workspace = true
|
||||
license.workspace = true
|
||||
publish = false
|
||||
|
||||
[features]
|
||||
test = []
|
||||
|
||||
[dependencies]
|
||||
tokio.workspace = true
|
||||
rustical_store = { workspace = true }
|
||||
|
||||
@@ -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)]
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user