feat(config): Parse RepoConfig
This commit is contained in:
parent
d5e9b14e3d
commit
c3f2266dc1
1 changed files with 45 additions and 2 deletions
|
@ -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)]
|
||||
pub struct Forge {
|
||||
forge_type: ForgeType,
|
||||
|
@ -78,8 +95,8 @@ impl Repo {
|
|||
}
|
||||
}
|
||||
#[cfg(test)]
|
||||
impl AsRef<Repo> for Repo {
|
||||
fn as_ref(&self) -> &Repo {
|
||||
impl AsRef<Self> 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(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue