diff --git a/src/git.rs b/src/git.rs index f9e99d2..f9d49c2 100644 --- a/src/git.rs +++ b/src/git.rs @@ -355,10 +355,22 @@ impl Repo { // fs::remove_dir_all(format!("{}{}", &self.path.as_ref(), &self.name.as_ref())) } fn check_is_valid_gitrepo(&self) -> bool { - // pub name: string, - // pub path: string, - // pub url: string, - todo!(); + if (self.name.is_none()) { + eprintln!("{:?} must have name: ", self.kind); + return false; + } + if (self.path.is_none()) { + eprintln!("{:?} must have path: ", self.kind); + return false; + } + if (self.url.is_none()) { + eprintln!("{:?} must have url: ", self.kind); + return false; + } + assert!(self.name.is_some()); + assert!(self.path.is_some()); + assert!(self.url.is_some()); + true } fn check_is_valid_githubrepo(&self) -> bool { todo!(); diff --git a/src/main.rs b/src/main.rs index 28bd714..6a6dc5f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -276,6 +276,64 @@ mod config { }); } } + #[test] + fn test_validators_config() { + use crate::git::SeriesItem; + let root = current_dir().expect("failed to get current dir"); + let config = Config::new( + &RelativePath::new("./src/test/config.yaml") + .to_logical_path(&root) + .into_os_string() + .into_string() + .expect("failed to turn config into string"), + ); + let series: Vec = vec![SeriesItem { + operation: "is_valid_kind", + closure: Box::new(Repo::is_valid_kind), + }]; + run_series!(config, series, true); + } + #[test] + #[should_panic] + fn test_validators_fail() { + use crate::git::SeriesItem; + let default_category = Category { + flags: Some(vec![]), + repos: Some(HashMap::new()), + links: Some(HashMap::new()), + }; + let mut config = Config { + categories: HashMap::new(), + }; + config + .categories + .insert(format!("{}", 0).to_string(), default_category); + for i in 0..=5 { + config + .categories + .get_mut(&format!("{}", 0).to_string()) + .expect("category not found") + .repos + .as_mut() + .expect("failed to get repo") + .insert( + format!("{}", i).to_string(), + // WE create a broken repo + Repo { + name: None, + path: Some("/tmp".to_string()), + url: Some("https://github.com/cafkafk/gg".to_string()), + flags: Some(vec![Clone, Push]), + kind: Some(crate::git::RepoKinds::GitRepo), + }, + ); + } + let series: Vec = vec![SeriesItem { + operation: "is_valid_kind", + closure: Box::new(Repo::is_valid_kind), + }]; + run_series!(config, series, true); + } } /* FIXME Unable to test with networking inside flake