Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use git root as scratch dir base for tests #536

Merged
merged 1 commit into from
Jan 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions plane/plane-tests/tests/common/test_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use plane::{
};
use std::{
net::Ipv4Addr,
path::PathBuf,
path::{Path, PathBuf},
sync::{Arc, Mutex},
};
use tracing::subscriber::DefaultGuard;
Expand Down Expand Up @@ -152,8 +152,23 @@ impl Drop for DnsServer {
}
}

fn get_project_root() -> PathBuf {
let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").expect("not in cargo project");
let manifest_dir_path = Path::new(&manifest_dir);
let project_root = manifest_dir_path
.ancestors()
.filter(|e| e.join(".git").exists())
.next()
.expect("not in git repo");
project_root.to_path_buf()
}

fn create_scratch_dir(name: &str) -> PathBuf {
let scratch_dir = PathBuf::from(format!("../test-scratch/{}", name));
let scratch_dir = {
let mut dir = get_project_root();
dir.push(format!("test-scratch/{}", name));
dir
};
std::fs::remove_dir_all(&scratch_dir).unwrap_or(());
std::fs::create_dir_all(&scratch_dir).unwrap();
scratch_dir
Expand Down
Loading