type TestResult = Result<(), Box>; mod server_repo_config { use assert2::let_assert; use crate::{RepoBranches, RepoConfig, RepoConfigSource}; use super::super::server_repo_config::*; #[test] fn should_not_return_repo_config_when_no_branches() { let src = ServerRepoConfig { repo: "".to_string(), branch: "".to_string(), gitdir: None, main: None, next: None, dev: None, }; let_assert!(None = src.repo_config()); } #[test] fn should_return_repo_config_when_branches() { let src = ServerRepoConfig { repo: "".to_string(), branch: "".to_string(), gitdir: None, main: Some("main".to_string()), next: Some("next".to_string()), dev: Some("dev".to_string()), }; let_assert!(Some(rc) = src.repo_config()); assert_eq!( rc, RepoConfig { branches: RepoBranches { main: "main".to_string(), next: "next".to_string(), dev: "dev".to_string() }, source: RepoConfigSource::Server } ); } } mod repo_config { use crate::{RepoBranches, RepoConfigSource}; use super::super::repo_config::*; use super::*; #[test] fn should_parse_toml() -> TestResult { let toml = r#" [branches] main = "main" next = "next" dev = "dev" "#; let rc = RepoConfig::load(toml)?; assert_eq!( rc, RepoConfig { branches: RepoBranches { main: "main".to_string(), next: "next".to_string(), dev: "dev".to_string(), }, source: RepoConfigSource::Repo // reading from repo is the default } ); Ok(()) } } mod forge_config { use std::collections::BTreeMap; use crate::{ForgeConfig, ForgeType, RepoAlias, ServerRepoConfig}; use super::*; #[test] fn should_return_repos() -> TestResult { let forge_type = ForgeType::MockForge; let hostname = "localhost".to_string(); let user = "bob".to_string(); let token = "alpha".to_string(); let red = ServerRepoConfig { repo: "red".to_string(), branch: "main".to_string(), main: None, next: None, dev: None, gitdir: None, }; let blue = ServerRepoConfig { repo: "blue".to_string(), branch: "main".to_string(), main: None, next: None, dev: None, gitdir: None, }; let mut repos = BTreeMap::new(); repos.insert("red".to_string(), red.clone()); repos.insert("blue".to_string(), blue.clone()); let fc = ForgeConfig { forge_type, hostname, user, token, repos, }; let returned_repos = fc.repos().collect::>(); assert_eq!( returned_repos, vec![ // alphabetical order by key (RepoAlias::new("blue"), &blue), (RepoAlias::new("red"), &red), ] ); Ok(()) } }