tests: add tests for Config
All checks were successful
Test / test (push) Successful in 5s

This commit is contained in:
Paul Campbell 2024-09-19 18:28:04 +01:00
parent 92811bc074
commit 64ddc6a6e6
4 changed files with 89 additions and 6 deletions

View file

@ -20,12 +20,12 @@ impl Config {
pub fn repo(&self) -> &str { pub fn repo(&self) -> &str {
&self.repo &self.repo
} }
pub fn server(&self) -> &str { // pub fn server(&self) -> &str {
&self.server // &self.server
} // }
pub fn auth_token(&self) -> Option<&str> { // pub fn auth_token(&self) -> Option<&str> {
self.auth_token.as_deref() // self.auth_token.as_deref()
} // }
pub fn prefix_pattern(&self) -> &Regex { pub fn prefix_pattern(&self) -> &Regex {
&self.prefix_pattern &self.prefix_pattern
} }

View file

@ -3,6 +3,9 @@ mod config;
mod line; mod line;
mod markers; mod markers;
#[cfg(test)]
mod tests;
pub use config::Config; pub use config::Config;
pub use line::Line; pub use line::Line;
pub use markers::FoundMarkers; pub use markers::FoundMarkers;

76
src/model/tests/config.rs Normal file
View file

@ -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<Config> {
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())
}

4
src/model/tests/mod.rs Normal file
View file

@ -0,0 +1,4 @@
//
use super::*;
mod config;