From 64ddc6a6e645df5f973e7618422e08ccf5f6c555 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Thu, 19 Sep 2024 18:28:04 +0100 Subject: [PATCH] tests: add tests for Config --- src/model/config.rs | 12 +++---- src/model/mod.rs | 3 ++ src/model/tests/config.rs | 76 +++++++++++++++++++++++++++++++++++++++ src/model/tests/mod.rs | 4 +++ 4 files changed, 89 insertions(+), 6 deletions(-) create mode 100644 src/model/tests/config.rs create mode 100644 src/model/tests/mod.rs diff --git a/src/model/config.rs b/src/model/config.rs index 4ff8c9e..605ad12 100644 --- a/src/model/config.rs +++ b/src/model/config.rs @@ -20,12 +20,12 @@ impl Config { pub fn repo(&self) -> &str { &self.repo } - pub fn server(&self) -> &str { - &self.server - } - pub fn auth_token(&self) -> Option<&str> { - self.auth_token.as_deref() - } + // pub fn server(&self) -> &str { + // &self.server + // } + // pub fn auth_token(&self) -> Option<&str> { + // self.auth_token.as_deref() + // } pub fn prefix_pattern(&self) -> &Regex { &self.prefix_pattern } diff --git a/src/model/mod.rs b/src/model/mod.rs index de93b0d..20f0054 100644 --- a/src/model/mod.rs +++ b/src/model/mod.rs @@ -3,6 +3,9 @@ mod config; mod line; mod markers; +#[cfg(test)] +mod tests; + pub use config::Config; pub use line::Line; pub use markers::FoundMarkers; diff --git a/src/model/tests/config.rs b/src/model/tests/config.rs new file mode 100644 index 0000000..a0cda62 --- /dev/null +++ b/src/model/tests/config.rs @@ -0,0 +1,76 @@ +use anyhow::Result; + +use crate::patterns::{issue_pattern, marker_pattern}; + +// +use super::*; + +#[test] +fn with_config_get_fs() -> Result<()> { + //given + let fs = kxio::fs::temp()?; + let config = a_config(fs.clone())?; + + //when + let result = config.fs(); + + //then + assert_eq!(result.base(), fs.base()); + + Ok(()) +} + +#[test] +fn with_config_get_prefix_pattern() -> Result<()> { + //given + let fs = kxio::fs::temp()?; + let config = a_config(fs)?; + + //when + let result = config.prefix_pattern(); + + //then + assert_eq!(result.to_string(), marker_pattern()?.to_string()); + + Ok(()) +} + +#[test] +fn with_config_get_issue_pattern() -> Result<()> { + //given + let fs = kxio::fs::temp()?; + let config = a_config(fs)?; + + //when + let result = config.issue_pattern(); + + //then + assert_eq!(result.to_string(), issue_pattern()?.to_string()); + + Ok(()) +} + +#[test] +fn with_config_get_repo() -> Result<()> { + //given + let fs = kxio::fs::temp()?; + let config = a_config(fs)?; + + //when + let result = config.repo(); + + //then + assert_eq!(result, "kemitix/test"); + + Ok(()) +} + +fn a_config(fs: kxio::fs::FileSystem) -> Result { + Ok(Config::builder() + .fs(fs) + .server("https://git.kemitix.net".to_string()) + .repo("kemitix/test".to_string()) + .prefix_pattern(marker_pattern()?) + .issue_pattern(issue_pattern()?) + .build()) +} diff --git a/src/model/tests/mod.rs b/src/model/tests/mod.rs new file mode 100644 index 0000000..c81d539 --- /dev/null +++ b/src/model/tests/mod.rs @@ -0,0 +1,4 @@ +// +use super::*; + +mod config;