kitchen-freezer/tests/sync.rs

48 lines
1.9 KiB
Rust
Raw Normal View History

2021-03-22 23:42:41 +01:00
#![cfg(feature = "integration_tests")]
mod scenarii;
2021-03-22 23:42:41 +01:00
use my_tasks::traits::CalDavSource;
2021-04-03 18:04:56 +02:00
use my_tasks::Provider;
2021-02-25 00:46:32 +01:00
use my_tasks::cache::Cache;
2021-03-01 23:39:16 +01:00
use my_tasks::calendar::cached_calendar::CachedCalendar;
2021-02-25 00:46:32 +01:00
#[tokio::test]
/// This test simulates a regular synchronisation between a local cache and a server.
/// Note that this uses a second cache to "mock" a server.
async fn test_regular_sync() {
2021-04-03 18:04:56 +02:00
let _ = env_logger::builder().is_test(true).try_init();
let scenarii = scenarii::basic_scenarii();
2021-04-03 18:04:56 +02:00
let mut provider = scenarii::populate_test_provider_before_sync(&scenarii).await;
2021-04-03 18:04:56 +02:00
print_provider(&provider, "before sync").await;
2021-04-03 18:04:56 +02:00
println!("\nsyncing...\n");
provider.sync().await.unwrap();
2021-02-25 00:46:32 +01:00
2021-04-03 18:04:56 +02:00
print_provider(&provider, "after sync").await;
2021-03-31 08:40:21 +02:00
2021-04-03 18:04:56 +02:00
// Check the contents of both sources are the same after sync
assert!(provider.remote().has_same_contents_than(provider.local()).await.unwrap());
2021-02-25 00:46:32 +01:00
2021-04-03 18:04:56 +02:00
// But also explicitely check that every item is expected
let expected_provider = scenarii::populate_test_provider_after_sync(&scenarii).await;
println!("\n");
print_provider(&expected_provider, "expected after sync").await;
2021-03-18 23:59:06 +01:00
2021-04-03 18:04:56 +02:00
assert!(provider.local() .has_same_contents_than(expected_provider.local() ).await.unwrap());
assert!(provider.remote().has_same_contents_than(expected_provider.remote()).await.unwrap());
}
/// Print the contents of the provider. This is usually used for debugging
#[allow(dead_code)]
async fn print_provider(provider: &Provider<Cache, CachedCalendar, Cache, CachedCalendar>, title: &str) {
2021-03-22 22:39:50 +01:00
let cals_server = provider.remote().get_calendars().await.unwrap();
2021-04-03 18:04:56 +02:00
println!("----Server, {}-------", title);
2021-03-21 19:05:22 +01:00
my_tasks::utils::print_calendar_list(&cals_server).await;
2021-02-27 11:58:40 +01:00
let cals_local = provider.local().get_calendars().await.unwrap();
2021-04-03 18:04:56 +02:00
println!("-----Local, {}-------", title);
2021-03-21 19:05:22 +01:00
my_tasks::utils::print_calendar_list(&cals_local).await;
2021-02-25 00:46:32 +01:00
}