aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMax Audron <audron@cocaine.farm>2024-03-27 13:40:54 +0100
committerMax Audron <audron@cocaine.farm>2024-03-27 13:40:54 +0100
commitf6dca0cc9694816db445005c89bc32245d8cdcf3 (patch)
tree3960a790dde8bb2c2e40767cd4d862b57b78ef91 /src
parentreorganize repo git impls (diff)
refactor tests
Diffstat (limited to 'src')
-rw-r--r--src/tests/mod.rs48
1 files changed, 25 insertions, 23 deletions
diff --git a/src/tests/mod.rs b/src/tests/mod.rs
index 3e0f7af..ca25c1f 100644
--- a/src/tests/mod.rs
+++ b/src/tests/mod.rs
@@ -1,13 +1,9 @@
+use std::path::{Path, PathBuf};
+
use crate::repo::*;
use anyhow::Result;
-use git2::Repository;
-
-thread_local! {
- static TEST_DIR: std::path::PathBuf = std::env::current_exe()
- .unwrap()
- .join(std::path::Path::new("../../tmp"));
-}
+use tracing::debug;
const REPOS: [&str; 5] = [
"repos/site/group/repo1",
@@ -17,43 +13,49 @@ const REPOS: [&str; 5] = [
"repos/site/group/subgroup/subsubgroup/repo4",
];
-fn prepare_repos() -> Result<()> {
+fn prepare_repos(path: &Path) -> Result<()> {
REPOS.iter().try_for_each(|repo| {
- let path = format!("{:?}/{}", TEST_DIR, repo);
+ let path = build_path(path, repo);
std::fs::create_dir_all(&path)?;
- let _repo = Repository::init(&path)?;
+ let _repo = gix::init(&path)?;
Ok::<(), anyhow::Error>(())
})
}
-fn clean_repos() -> Result<()> {
- REPOS.iter().try_for_each(|repo| {
- let path = format!("{:?}/{}", TEST_DIR, repo);
- std::fs::remove_dir_all(&path)?;
+fn build_path(path: &Path, repo: &str) -> PathBuf {
+ let mut path = path.to_owned();
+ path.push(repo);
+ return path;
+}
- Ok::<(), anyhow::Error>(())
- })
+fn build_path_string(path: &Path, repo: &str) -> String {
+ let mut path = path.to_owned();
+ path.push(repo);
+ return path.into_os_string().into_string().unwrap();
}
#[tokio::test]
async fn search_repos() -> Result<()> {
tracing_subscriber::fmt::init();
- prepare_repos()?;
+ let test_dir = tempfile::tempdir()?;
+ let test_path = test_dir.path();
+ debug!("test files placed in: {:?}", test_dir.path());
+
+ prepare_repos(test_path)?;
let mut left: Vec<String> = vec![
- format!("{:?}/repos/site/group/repo1", TEST_DIR),
- format!("{:?}/repos/site/group/repo2", TEST_DIR),
- format!("{:?}/repos/site/group/subgroup/repo3", TEST_DIR),
- format!("{:?}/repos/site/group/subgroup/subsubgroup/repo4", TEST_DIR),
+ build_path_string(test_path, "repos/site/group/repo1"),
+ build_path_string(test_path, "repos/site/group/repo2"),
+ build_path_string(test_path, "repos/site/group/subgroup/repo3"),
+ build_path_string(test_path, "repos/site/group/subgroup/subsubgroup/repo4"),
];
- let right = Repos::from_local(&format!("{:?}/repos", TEST_DIR), "");
+ let right = Repos::from_local(&build_path_string(test_path, "repos"), "");
let mut right: Vec<&str> = right.iter().map(|x| x.0.as_str()).collect();
assert_eq!(left.sort(), right.sort_unstable());
- clean_repos()?;
Ok(())
}