@@ 12,14 12,14 @@ use std::path::{Path, PathBuf};
use std::time::Duration;
#[serde_as]
-#[derive(Debug, Deserialize)]
+#[derive(Debug, Deserialize, PartialEq)]
pub(crate) struct Config {
#[serde(default = "get_default_log_level")]
#[serde_as(as = "DisplayFromStr")]
pub(crate) log_level: Level,
- pub(crate) feed_cookie_value: String,
pub(crate) feed_url: String,
+ pub(crate) feed_cookie_value: String,
pub(crate) feed_max_new_entries: usize,
pub(crate) last_processed_id_filename: PathBuf,
@@ 42,3 42,30 @@ pub(crate) fn load_config(path: &Path) -> Result<Config> {
let config: Config = toml::from_str(&text)?;
Ok(config)
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn test_load_config() {
+ let expected = Config {
+ log_level: Level::Error,
+
+ feed_url: "https://forum.example.com/index.php?action=.xml;type=atom".to_owned(),
+ feed_cookie_value: "<insert value of your 'SMFCookie10' cookie>".to_owned(),
+ feed_max_new_entries: 5,
+
+ last_processed_id_filename: PathBuf::from("last_processed_id"),
+
+ webhook_text_template: "{author} posted to forum: \"{title}\" - <{url}>".to_owned(),
+ webhook_url: "http://127.0.0.1:8080/<your-webhook-path>".to_owned(),
+
+ interval: None,
+ };
+
+ let actual = load_config(Path::new("config_example.toml"));
+ assert!(actual.is_ok());
+ assert_eq!(actual.unwrap(), expected);
+ }
+}