store: test preparations

This commit is contained in:
Lennart
2025-06-27 13:58:14 +02:00
parent fe78a82806
commit b54fbebe7c
4 changed files with 19 additions and 10 deletions

View File

@@ -11,6 +11,9 @@ mod secret;
mod subscription_store; mod subscription_store;
pub mod synctoken; pub mod synctoken;
#[cfg(test)]
pub mod tests;
pub use addressbook_store::AddressbookStore; pub use addressbook_store::AddressbookStore;
pub use calendar_store::CalendarStore; pub use calendar_store::CalendarStore;
pub use combined_calendar_store::CombinedCalendarStore; pub use combined_calendar_store::CombinedCalendarStore;

View File

View File

@@ -8,6 +8,9 @@ pub mod error;
pub mod principal_store; pub mod principal_store;
pub mod subscription_store; pub mod subscription_store;
#[cfg(test)]
pub mod tests;
#[derive(Debug, Clone, Serialize, sqlx::Type)] #[derive(Debug, Clone, Serialize, sqlx::Type)]
#[serde(rename_all = "kebab-case")] #[serde(rename_all = "kebab-case")]
pub(crate) enum ChangeOperation { pub(crate) enum ChangeOperation {
@@ -42,13 +45,3 @@ pub async fn create_db_pool(db_url: &str, migrate: bool) -> Result<Pool<Sqlite>,
} }
Ok(db) Ok(db)
} }
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 create_test_store() -> Result<SqliteStore, sqlx::Error> {
Ok(SqliteStore::new(create_test_db().await?))
}

View File

@@ -0,0 +1,13 @@
use crate::SqliteStore;
use sqlx::SqlitePool;
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)
}
#[tokio::test]
async fn test_create_store() {
SqliteStore::new(create_test_db().await.unwrap());
}