fix(status): get status in obj and fix tests env dir
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -89,7 +89,6 @@ fn all_folder_current() -> io::Result<()> {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn relative_path() -> io::Result<()> {
|
||||
let mut client = ClientTest::new("status__all_folder_current").init();
|
||||
|
||||
@@ -100,9 +99,9 @@ fn relative_path() -> io::Result<()> {
|
||||
status_expected(&client.get_config(), vec![], vec!["foor", "dir"]);
|
||||
|
||||
client.exec_ok("add dir");
|
||||
// client.set_execution_path("dir");
|
||||
client.set_execution_path("dir");
|
||||
status_expected(
|
||||
&client.new_config("dir"),
|
||||
&client.get_config(),
|
||||
vec!["foo", "bar"],
|
||||
vec!["../foor"],
|
||||
);
|
||||
Reference in New Issue
Block a user