From 66d8014872996e9e1ef55d2022ded14225948c39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christina=20S=C3=B8rensen?= Date: Mon, 24 Jul 2023 07:19:34 +0200 Subject: [PATCH] feat: kind gitrepo validator+testing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christina Sørensen --- src/git.rs | 20 ++++++++++++++---- src/main.rs | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 4 deletions(-) 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