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::new("".to_string(), "".to_string(), None, None, None, None); let_assert!(None = src.repo_config()); } #[test] fn should_return_repo_config_when_branches() { let src = ServerRepoConfig::new( "".to_string(), "".to_string(), None, Some("main".to_string()), Some("next".to_string()), Some("dev".to_string()), ); let_assert!(Some(rc) = src.repo_config()); assert_eq!( rc, RepoConfig::new( RepoBranches::new("main".to_string(), "next".to_string(), "dev".to_string()), 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::new( RepoBranches::new("main".to_string(), "next".to_string(), "dev".to_string(),), 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::new( "red".to_string(), "main".to_string(), None, None, None, None, ); let blue = ServerRepoConfig::new( "blue".to_string(), "main".to_string(), None, None, None, None, ); let mut repos = BTreeMap::new(); repos.insert("red".to_string(), red.clone()); repos.insert("blue".to_string(), blue.clone()); let fc = ForgeConfig::new(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(()) } }