From c3f2266dc1ab507a9f217c005bbee7372d8f3dfb Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 8 Apr 2024 09:54:20 +0100 Subject: [PATCH] feat(config): Parse RepoConfig --- src/server/config.rs | 47 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/src/server/config.rs b/src/server/config.rs index 596c69ab..42c04d5b 100644 --- a/src/server/config.rs +++ b/src/server/config.rs @@ -25,6 +25,23 @@ impl ServerConfig { } } +#[derive(Debug, PartialEq, Eq, Deserialize)] +pub struct RepoConfig { + branches: RepoBranches, +} +impl RepoConfig { + #[allow(dead_code)] + pub(crate) fn load(toml: &str) -> Result> { + toml::from_str(toml).map_err(OneOf::new) + } +} +#[derive(Debug, PartialEq, Eq, Deserialize)] +pub struct RepoBranches { + main: String, + next: String, + dev: String, +} + #[derive(Debug, PartialEq, Eq, Deserialize)] pub struct Forge { forge_type: ForgeType, @@ -78,8 +95,8 @@ impl Repo { } } #[cfg(test)] -impl AsRef for Repo { - fn as_ref(&self) -> &Repo { +impl AsRef for Repo { + fn as_ref(&self) -> &Self { self } } @@ -242,4 +259,30 @@ mod tests { Ok(()) } + + #[test] + fn test_repo_config_load() -> Result<(), OneOf<(toml::de::Error,)>> { + let toml = r#" + [branches] + main = "main" + next = "next" + dev = "dev" + + [options] + "#; + let config = RepoConfig::load(toml)?; + + assert_eq!( + config, + RepoConfig { + branches: RepoBranches { + main: "main".to_string(), + next: "next".to_string(), + dev: "dev".to_string(), + }, + } + ); + + Ok(()) + } }