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(()) + } }