From 92102ebfc0efde98ebdf20825498a0daa3e6c8ea Mon Sep 17 00:00:00 2001 From: Lennart <18233294+lennart-k@users.noreply.github.com> Date: Mon, 26 Feb 2024 16:29:32 +0100 Subject: [PATCH] TOML store, optional path for unit testing --- crates/store/src/toml_store.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/crates/store/src/toml_store.rs b/crates/store/src/toml_store.rs index 3270d7c..f2a3d54 100644 --- a/crates/store/src/toml_store.rs +++ b/crates/store/src/toml_store.rs @@ -10,7 +10,7 @@ use tokio::{fs::File, io::AsyncWriteExt}; pub struct TomlCalendarStore { calendars: HashMap, events: HashMap>, - path: String, + path: Option, } impl TomlCalendarStore { @@ -18,14 +18,24 @@ impl TomlCalendarStore { TomlCalendarStore { calendars: HashMap::new(), events: HashMap::new(), - path, + path: Some(path), + } + } + + pub fn test() -> Self { + TomlCalendarStore { + calendars: HashMap::new(), + events: HashMap::new(), + path: None, } } pub async fn save(&self) -> Result<()> { - let mut file = File::create(&self.path).await?; let output = toml::to_string_pretty(&self)?; - file.write_all(output.as_bytes()).await?; + if let Some(path) = &self.path { + let mut file = File::create(path).await?; + file.write_all(output.as_bytes()).await?; + } Ok(()) } }