refactor(config): compare whole server config in one go

This commit is contained in:
Paul Campbell 2024-04-08 12:03:19 +01:00
parent be01d106a4
commit aaaa975911
2 changed files with 28 additions and 21 deletions

View file

@ -30,7 +30,7 @@ actix-rt = "2.9"
[dev-dependencies] [dev-dependencies]
# Testing # Testing
assert2 = "0.3" # assert2 = "0.3"
test-log = "0.2" test-log = "0.2"
anyhow = "1.0" anyhow = "1.0"

View file

@ -77,13 +77,6 @@ pub struct Repo {
branch: String, branch: String,
} }
impl Repo { impl Repo {
#[cfg(test)]
pub fn new(repo: &str, branch: &str) -> Self {
Self {
repo: repo.to_string(),
branch: branch.to_string(),
}
}
#[allow(dead_code)] #[allow(dead_code)]
pub fn repo(&self) -> RepoPath { pub fn repo(&self) -> RepoPath {
RepoPath(self.repo.clone()) RepoPath(self.repo.clone())
@ -227,7 +220,6 @@ impl Display for ForgeType {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use assert2::let_assert;
use crate::filesystem::FileSystem; use crate::filesystem::FileSystem;
@ -251,18 +243,33 @@ mod tests {
) )
.map_err(OneOf::new)?; .map_err(OneOf::new)?;
let config = ServerConfig::load(&fs)?; let config = ServerConfig::load(&fs)?;
let_assert!(Some(default) = config.forge.get("default")); let expected = ServerConfig {
assert_eq!(default.forge_type, ForgeType::ForgeJo); forge: HashMap::from([(
assert_eq!(default.hostname, "git.example.net".to_string()); "default".to_string(),
assert_eq!(default.user, "Bob".to_string()); Forge {
assert_eq!( forge_type: ForgeType::ForgeJo,
default.repos.get("hello"), hostname: "git.example.net".to_string(),
Some(Repo::new("user/hello", "main").as_ref()) user: "Bob".to_string(),
); repos: HashMap::from([
assert_eq!( (
default.repos.get("world"), "hello".to_string(),
Some(Repo::new("user/world", "master").as_ref()) Repo {
); repo: "user/hello".to_string(),
branch: "main".to_string(),
},
),
(
"world".to_string(),
Repo {
repo: "user/world".to_string(),
branch: "master".to_string(),
},
),
]),
},
)]),
};
assert_eq!(config, expected);
Ok(()) Ok(())
} }