feat: push deletion

This commit is contained in:
grimhilt
2024-05-02 18:36:09 +02:00
parent 4504b98112
commit 939b6f2fe3
7 changed files with 70 additions and 17 deletions

View File

@@ -1,4 +1,3 @@
mod utils;
use utils::{utils::*, status_utils::*, server::ServerTest, client::ClientTest};
@@ -151,7 +150,6 @@ mod push_tests {
// remove it
let _ = client.remove_file("file1");
client.run_cmd_ok("add file1");
dbg!(client.get_status());
client.run_cmd_ok("push");
// tests
@@ -161,4 +159,27 @@ mod push_tests {
client.clean();
server.clean();
}
#[test]
fn push_dir_deletion() {
let (mut client, mut server) = init_test();
// push dir and file2
let _ = client.add_dir("dir");
let _ = client.add_file("dir/file2", "bar");
client.run_cmd_ok("add dir");
client.run_cmd_ok("push");
// tests
assert!(server.has_file("dir/file2", "bar"));
// push deletion
let _ = client.remove_dir("dir");
client.run_cmd_ok("add dir");
client.run_cmd_ok("push");
assert!(server.has_not_dir("dir"));
client.clean();
server.clean();
}
}

View File

@@ -104,6 +104,14 @@ impl ClientTest {
Ok(())
}
pub fn remove_dir(&mut self, name: &str) -> std::io::Result<()> {
let mut path = self.volume.clone();
path.push_str("/");
path.push_str(name);
fs::remove_dir_all(path)?;
Ok(())
}
pub fn has_file(&mut self, file: &str, content: &str) -> bool {
let full_path = PathBuf::from(self.volume.clone()).join(file);

View File

@@ -36,3 +36,15 @@ pub fn has_not_file(full_path: PathBuf, file: &str, test_id: String) -> bool
return true;
}
#[cfg(test)]
pub fn has_not_dir(full_path: PathBuf, dir: &str, test_id: String) -> bool
{
if full_path.exists() {
println!("id: {}", test_id.clone());
eprintln!("Dir '{}' exists but it shouldn't", dir);
return false;
}
return true;
}

View File

@@ -113,5 +113,11 @@ impl ServerTest {
let full_path = self.volume.clone().join(file);
files_utils::has_not_file(full_path, file, self.test_id.clone())
}
pub fn has_not_dir(&mut self, dir: &str) -> bool {
let full_path = self.volume.clone().join(dir);
dbg!(full_path.clone());
files_utils::has_not_file(full_path, dir, self.test_id.clone())
}
}