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]
# Testing
assert2 = "0.3"
# assert2 = "0.3"
test-log = "0.2"
anyhow = "1.0"

View file

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