refactor(blob): use object trait to create blob
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
use rand::{distributions::Alphanumeric, Rng};
|
||||
use std::env;
|
||||
|
||||
mod utils;
|
||||
use utils::{server::ServerTest, client::ClientTest};
|
||||
@@ -61,4 +60,46 @@ mod push_tests {
|
||||
client.clean();
|
||||
server.clean();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn push_dir() {
|
||||
let id = get_random_test_id();
|
||||
let mut server = ServerTest::new(id.clone()).init();
|
||||
let mut client = ClientTest::new(id).init();
|
||||
|
||||
let _ = client.add_dir("dir");
|
||||
let _ = client.add_file("dir/file2", "bar");
|
||||
|
||||
// push dir and file2
|
||||
client.run_cmd_ok("add file2");
|
||||
client.run_cmd_ok("push");
|
||||
|
||||
// tests
|
||||
assert!(server.has_file("dir/file2", "bar"));
|
||||
|
||||
client.clean();
|
||||
server.clean();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn push_all() {
|
||||
let id = get_random_test_id();
|
||||
let mut server = ServerTest::new(id.clone()).init();
|
||||
let mut client = ClientTest::new(id).init();
|
||||
|
||||
let _ = client.add_file("file1", "foo");
|
||||
let _ = client.add_dir("dir");
|
||||
let _ = client.add_file("dir/file2", "bar");
|
||||
|
||||
// push dir and file2
|
||||
client.run_cmd_ok("add *");
|
||||
client.run_cmd_ok("push");
|
||||
|
||||
// tests
|
||||
assert!(server.has_file("file1", "foo"));
|
||||
assert!(server.has_file("dir/file2", "bar"));
|
||||
|
||||
client.clean();
|
||||
server.clean();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,8 +23,6 @@ impl ClientTest {
|
||||
let mut exe_path = env::current_dir().unwrap();
|
||||
exe_path = exe_path.join("target/debug/nextsync");
|
||||
|
||||
// let _ = env::set_current_dir(vol.clone());
|
||||
|
||||
// build the client
|
||||
ClientTest {
|
||||
user: String::from("admin"),
|
||||
@@ -50,13 +48,8 @@ impl ClientTest {
|
||||
|
||||
}
|
||||
|
||||
pub fn clean(mut self) -> Self {
|
||||
pub fn clean(self) -> Self {
|
||||
let _ = fs::remove_dir_all(&self.volume);
|
||||
|
||||
// set back the current dir
|
||||
self.exe_path.pop();
|
||||
dbg!(self.exe_path.clone());
|
||||
let _ = env::set_current_dir(self.exe_path.clone());
|
||||
self
|
||||
}
|
||||
|
||||
@@ -80,6 +73,14 @@ impl ClientTest {
|
||||
return output;
|
||||
}
|
||||
|
||||
pub fn add_dir(&mut self, name: &str) -> std::io::Result<()> {
|
||||
let mut path = self.volume.clone();
|
||||
path.push_str("/");
|
||||
path.push_str(name);
|
||||
let _ = fs::create_dir_all(path)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn add_file(&mut self, name: &str, content: &str) -> std::io::Result<()> {
|
||||
let mut path = self.volume.clone();
|
||||
path.push_str("/");
|
||||
|
||||
@@ -93,7 +93,7 @@ impl ServerTest {
|
||||
let full_path = self.volume.clone().join(file);
|
||||
|
||||
if !full_path.exists() {
|
||||
eprintln!("File '{}' does't exists on the server", file);
|
||||
eprintln!("File '{}' doesn't exists on the server", file);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user