mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 19:22:26 +00:00
tiny steps towards unit testing for each resource
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -2816,6 +2816,7 @@ dependencies = [
|
|||||||
"rustical_dav_push",
|
"rustical_dav_push",
|
||||||
"rustical_ical",
|
"rustical_ical",
|
||||||
"rustical_store",
|
"rustical_store",
|
||||||
|
"rustical_store_sqlite",
|
||||||
"rustical_xml",
|
"rustical_xml",
|
||||||
"serde",
|
"serde",
|
||||||
"sha2",
|
"sha2",
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ repository.workspace = true
|
|||||||
license.workspace = true
|
license.workspace = true
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
rustical_store_sqlite = { workspace = true, features = ["test"] }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
axum.workspace = true
|
axum.workspace = true
|
||||||
axum-extra.workspace = true
|
axum-extra.workspace = true
|
||||||
|
|||||||
@@ -11,8 +11,10 @@ mod service;
|
|||||||
pub use service::*;
|
pub use service::*;
|
||||||
mod prop;
|
mod prop;
|
||||||
pub use prop::*;
|
pub use prop::*;
|
||||||
|
#[cfg(test)]
|
||||||
|
pub mod tests;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct PrincipalResource {
|
pub struct PrincipalResource {
|
||||||
principal: Principal,
|
principal: Principal,
|
||||||
members: Vec<String>,
|
members: Vec<String>,
|
||||||
|
|||||||
39
crates/caldav/src/principal/tests.rs
Normal file
39
crates/caldav/src/principal/tests.rs
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
use crate::principal::PrincipalResourceService;
|
||||||
|
use rustical_dav::resource::ResourceService;
|
||||||
|
use rustical_store::auth::{AuthenticationProvider, Principal, PrincipalType};
|
||||||
|
use rustical_store_sqlite::tests::get_test_stores;
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_principal_resource() {
|
||||||
|
let (_, cal_store, sub_store, auth_provider, _) = get_test_stores().await;
|
||||||
|
let service = PrincipalResourceService {
|
||||||
|
cal_store,
|
||||||
|
sub_store,
|
||||||
|
auth_provider: auth_provider.clone(),
|
||||||
|
};
|
||||||
|
|
||||||
|
auth_provider
|
||||||
|
.insert_principal(
|
||||||
|
Principal {
|
||||||
|
id: "user".to_owned(),
|
||||||
|
displayname: None,
|
||||||
|
memberships: vec![],
|
||||||
|
password: None,
|
||||||
|
principal_type: PrincipalType::Individual,
|
||||||
|
},
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
assert!(matches!(
|
||||||
|
service.get_resource(&("anonymous".to_owned(),), true).await,
|
||||||
|
Err(crate::Error::NotFound)
|
||||||
|
));
|
||||||
|
|
||||||
|
let _principal_resource = service
|
||||||
|
.get_resource(&("user".to_owned(),), true)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
@@ -7,6 +7,9 @@ repository.workspace = true
|
|||||||
license.workspace = true
|
license.workspace = true
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
|
[features]
|
||||||
|
test = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tokio.workspace = true
|
tokio.workspace = true
|
||||||
rustical_store = { workspace = true }
|
rustical_store = { workspace = true }
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ pub mod error;
|
|||||||
pub mod principal_store;
|
pub mod principal_store;
|
||||||
pub mod subscription_store;
|
pub mod subscription_store;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(any(test, feature = "test"))]
|
||||||
pub mod tests;
|
pub mod tests;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, sqlx::Type)]
|
#[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 sqlx::SqlitePool;
|
||||||
|
use std::sync::Arc;
|
||||||
|
use tokio::sync::mpsc::Receiver;
|
||||||
|
|
||||||
pub async fn create_test_db() -> Result<SqlitePool, sqlx::Error> {
|
pub async fn get_test_stores() -> (
|
||||||
let db = SqlitePool::connect("sqlite::memory:").await?;
|
Arc<impl AddressbookStore>,
|
||||||
sqlx::migrate!("./migrations").run(&db).await?;
|
Arc<impl CalendarStore>,
|
||||||
Ok(db)
|
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]
|
#[tokio::test]
|
||||||
async fn test_create_store() {
|
async fn test_create_store() {
|
||||||
SqliteStore::new(create_test_db().await.unwrap());
|
get_test_stores().await;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user