From aaaa9759115128c000c2551a36328614e9114120 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 8 Apr 2024 12:03:19 +0100 Subject: [PATCH] refactor(config): compare whole server config in one go --- Cargo.toml | 2 +- src/server/config.rs | 47 +++++++++++++++++++++++++------------------- 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 493a45a3..c12689db 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,7 +30,7 @@ actix-rt = "2.9" [dev-dependencies] # Testing -assert2 = "0.3" +# assert2 = "0.3" test-log = "0.2" anyhow = "1.0" diff --git a/src/server/config.rs b/src/server/config.rs index 91444bff..0d825c58 100644 --- a/src/server/config.rs +++ b/src/server/config.rs @@ -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(()) }