fix(status): get status in obj and fix tests env dir

This commit is contained in:
grimhilt
2024-09-14 13:59:00 +02:00
parent a69a71d843
commit cd7b225145
4 changed files with 53 additions and 20 deletions

View File

@@ -6,11 +6,18 @@ use std::io::{self, Write};
use std::path::PathBuf;
use std::process::{Command, Output};
use std::str;
use std::sync::LazyLock;
// Absolute path of the nextsync executable
static EXE_PATH: LazyLock<PathBuf> = LazyLock::new(|| {
let mut exe_path = env::current_dir().unwrap();
exe_path = exe_path.join("target/debug/nextsync");
exe_path
});
pub struct ClientTest {
volume: String, // temp dir for the test
pub test_id: String, // name of the test (e.g nextsync_rand)
exe_path: PathBuf, // absolute path of nextsync executable
}
pub fn get_random_test_id() -> String {
@@ -23,6 +30,9 @@ pub fn get_random_test_id() -> String {
impl ClientTest {
pub fn new(id: &str) -> Self {
// init the EXE_PATH for the first time
let _ = &*EXE_PATH;
let mut test_id = id.to_string();
test_id.push_str("_");
test_id.push_str(&get_random_test_id());
@@ -33,15 +43,13 @@ impl ClientTest {
let _ = fs::remove_dir_all(&vol);
let _ = fs::create_dir_all(&vol);
// get nextsync path
let mut exe_path = env::current_dir().unwrap();
exe_path = exe_path.join("target/debug/nextsync");
// Setup the current dir to the local repo
env::set_current_dir(&vol).unwrap();
// build the client
ClientTest {
volume: vol,
test_id,
exe_path,
}
}
@@ -72,6 +80,14 @@ impl ClientTest {
Config::from(Some(&full_path))
}
pub fn set_execution_path(&self, path: &str) {
let mut new_execution_path = self.volume.clone();
new_execution_path.push_str("/");
new_execution_path.push_str(path);
env::set_current_dir(new_execution_path).unwrap();
}
pub fn ok(self) -> io::Result<()> {
fs::remove_dir_all(&self.volume)?;
Ok(())
@@ -90,7 +106,7 @@ impl ClientTest {
}
pub fn exec(&mut self, args: &str) -> Output {
let output = Command::new(self.exe_path.to_str().unwrap())
let output = Command::new(&*EXE_PATH.to_str().unwrap())
.current_dir(self.volume.clone())
.args(args.split(" "))
.output()