feat(config): Parse RepoConfig

This commit is contained in:
Paul Campbell 2024-04-08 09:54:20 +01:00
parent d5e9b14e3d
commit c3f2266dc1

View file

@ -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<Self, OneOf<(toml::de::Error,)>> {
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)] #[derive(Debug, PartialEq, Eq, Deserialize)]
pub struct Forge { pub struct Forge {
forge_type: ForgeType, forge_type: ForgeType,
@ -78,8 +95,8 @@ impl Repo {
} }
} }
#[cfg(test)] #[cfg(test)]
impl AsRef<Repo> for Repo { impl AsRef<Self> for Repo {
fn as_ref(&self) -> &Repo { fn as_ref(&self) -> &Self {
self self
} }
} }
@ -242,4 +259,30 @@ mod tests {
Ok(()) 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(())
}
} }