store: experiments with unit tests

This commit is contained in:
Lennart
2024-03-29 15:35:15 +01:00
parent 320e1a7462
commit 69fec2f8b2
4 changed files with 164 additions and 158 deletions

View File

@@ -1,172 +1,33 @@
use rstest::rstest;
use rstest_reuse::{self, apply, template};
use rustical_store::calendar::CalendarStore;
use rustical_store::sqlite_store::create_test_store;
use rustical_store::toml_store::TomlCalendarStore;
const TIMEZONE: &str = "BEGIN:VCALENDAR\r
BEGIN:VTIMEZONE\r
TZID:Europe/Berlin\r
LAST-MODIFIED:20230104T023643Z\r
TZURL:https://www.tzurl.org/zoneinfo/Europe/Berlin\r
X-LIC-LOCATION:Europe/Berlin\r
X-PROLEPTIC-TZNAME:LMT\r
BEGIN:STANDARD\r
TZNAME:CET\r
TZOFFSETFROM:+005328\r
TZOFFSETTO:+0100\r
DTSTART:18930401T000632\r
END:STANDARD\r
BEGIN:DAYLIGHT\r
TZNAME:CEST\r
TZOFFSETFROM:+0100\r
TZOFFSETTO:+0200\r
DTSTART:19160430T230000\r
RDATE:19400401T020000\r
RDATE:19430329T020000\r
RDATE:19460414T020000\r
RDATE:19470406T030000\r
RDATE:19480418T020000\r
RDATE:19490410T020000\r
RDATE:19800406T020000\r
END:DAYLIGHT\r
BEGIN:STANDARD\r
TZNAME:CET\r
TZOFFSETFROM:+0200\r
TZOFFSETTO:+0100\r
DTSTART:19161001T010000\r
RDATE:19421102T030000\r
RDATE:19431004T030000\r
RDATE:19441002T030000\r
RDATE:19451118T030000\r
RDATE:19461007T030000\r
END:STANDARD\r
BEGIN:DAYLIGHT\r
TZNAME:CEST\r
TZOFFSETFROM:+0100\r
TZOFFSETTO:+0200\r
DTSTART:19170416T020000\r
RRULE:FREQ=YEARLY;UNTIL=19180415T010000Z;BYMONTH=4;BYDAY=3MO\r
END:DAYLIGHT\r
BEGIN:STANDARD\r
TZNAME:CET\r
TZOFFSETFROM:+0200\r
TZOFFSETTO:+0100\r
DTSTART:19170917T030000\r
RRULE:FREQ=YEARLY;UNTIL=19180916T010000Z;BYMONTH=9;BYDAY=3MO\r
END:STANDARD\r
BEGIN:DAYLIGHT\r
TZNAME:CEST\r
TZOFFSETFROM:+0100\r
TZOFFSETTO:+0200\r
DTSTART:19440403T020000\r
RRULE:FREQ=YEARLY;UNTIL=19450402T010000Z;BYMONTH=4;BYDAY=1MO\r
END:DAYLIGHT\r
BEGIN:DAYLIGHT\r
TZNAME:CEMT\r
TZOFFSETFROM:+0200\r
TZOFFSETTO:+0300\r
DTSTART:19450524T010000\r
RDATE:19470511T020000\r
END:DAYLIGHT\r
BEGIN:DAYLIGHT\r
TZNAME:CEST\r
TZOFFSETFROM:+0300\r
TZOFFSETTO:+0200\r
DTSTART:19450924T030000\r
RDATE:19470629T030000\r
END:DAYLIGHT\r
BEGIN:STANDARD\r
TZNAME:CET\r
TZOFFSETFROM:+0100\r
TZOFFSETTO:+0100\r
DTSTART:19460101T000000\r
RDATE:19800101T000000\r
END:STANDARD\r
BEGIN:STANDARD\r
TZNAME:CET\r
TZOFFSETFROM:+0200\r
TZOFFSETTO:+0100\r
DTSTART:19471005T030000\r
RRULE:FREQ=YEARLY;UNTIL=19491002T010000Z;BYMONTH=10;BYDAY=1SU\r
END:STANDARD\r
BEGIN:STANDARD\r
TZNAME:CET\r
TZOFFSETFROM:+0200\r
TZOFFSETTO:+0100\r
DTSTART:19800928T030000\r
RRULE:FREQ=YEARLY;UNTIL=19950924T010000Z;BYMONTH=9;BYDAY=-1SU\r
END:STANDARD\r
BEGIN:DAYLIGHT\r
TZNAME:CEST\r
TZOFFSETFROM:+0100\r
TZOFFSETTO:+0200\r
DTSTART:19810329T020000\r
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU\r
END:DAYLIGHT\r
BEGIN:STANDARD\r
TZNAME:CET\r
TZOFFSETFROM:+0200\r
TZOFFSETTO:+0100\r
DTSTART:19961027T030000\r
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU\r
END:STANDARD\r
END:VTIMEZONE\r
END:VCALENDAR\r
";
const EVENT: &str = "BEGIN:VCALENDAR\r
CALSCALE:GREGORIAN\r
PRODID:-//Ximian//NONSGML Evolution Calendar//EN\r
VERSION:2.0\r
BEGIN:VTIMEZONE\r
TZID:Europe/Berlin\r
X-LIC-LOCATION:Europe/Berlin\r
BEGIN:DAYLIGHT\r
TZNAME:CEST\r
TZOFFSETFROM:+0100\r
TZOFFSETTO:+0200\r
DTSTART:19810329T020000\r
RRULE:FREQ=YEARLY;UNTIL=20370329T010000Z;BYDAY=-1SU;BYMONTH=3\r
END:DAYLIGHT\r
BEGIN:STANDARD\r
TZNAME:CET\r
TZOFFSETFROM:+0200\r
TZOFFSETTO:+0100\r
DTSTART:19961027T030000\r
RRULE:FREQ=YEARLY;UNTIL=20361026T010000Z;BYDAY=-1SU;BYMONTH=10\r
END:STANDARD\r
END:VTIMEZONE\r
BEGIN:VEVENT\r
UID:67d830c3e681950b6a12f7c287b316269a19fcf7\r
DTSTAMP:20230831T102923Z\r
DTSTART;TZID=Europe/Berlin:20230829T043000\r
DTEND;TZID=Europe/Berlin:20230829T045500\r
SEQUENCE:2\r
SUMMARY:asdjlk\r
TRANSP:OPAQUE\r
CLASS:PUBLIC\r
CREATED:20230831T103040Z\r
LAST-MODIFIED:20230831T103040Z\r
END:VEVENT\r
END:VCALENDAR\r
";
#[tokio::test]
async fn test_init_sqlite() {
let store = create_test_store().await.unwrap();
store.get_events("asd").await.unwrap();
}
const TIMEZONE: &str = include_str!("examples/timezone.ics");
const EVENT: &str = include_str!("examples/event.ics");
#[template]
#[rstest]
#[case::toml(async {TomlCalendarStore::test()})]
#[case::sqlite(async {create_test_store().await.unwrap() })]
#[tokio::test]
async fn test_create_event<CS: CalendarStore>(
#[future]
async fn cal_store<CS: CalendarStore>(
#[future(awt)]
#[case]
store: CS,
mut store: CS,
) {
let mut store = store.await;
}
#[apply(cal_store)]
#[tokio::test]
async fn test_init<CS: CalendarStore>(store: CS) {
store.get_events("asd").await.unwrap();
}
#[apply(cal_store)]
#[tokio::test]
async fn test_create_event<CS: CalendarStore>(store: CS) {
let mut store = store;
store
.insert_calendar(
"test".to_owned(),