fix(tests): fix testsuite allow to pass push
This commit is contained in:
parent
7180647d26
commit
a1b9cde71a
@ -13,15 +13,15 @@ pub fn init() {
|
||||
};
|
||||
|
||||
// check if dir is empty
|
||||
if let Ok(entries) = read_folder(path.clone()) {
|
||||
if entries.len() != 0 {
|
||||
eprintln!("fatal: destination path '{}' already exists and is not an empty directory.", path.display());
|
||||
std::process::exit(1);
|
||||
}
|
||||
} else {
|
||||
eprintln!("fatal: cannot open the destination directory");
|
||||
std::process::exit(1);
|
||||
}
|
||||
// if let Ok(entries) = read_folder(path.clone()) {
|
||||
// if entries.len() != 0 {
|
||||
// eprintln!("fatal: destination path '{}' already exists and is not an empty directory.", path.display());
|
||||
// std::process::exit(1);
|
||||
// }
|
||||
// } else {
|
||||
// eprintln!("fatal: cannot open the destination directory");
|
||||
// std::process::exit(1);
|
||||
// }
|
||||
|
||||
let builder = DirBuilder::new();
|
||||
|
||||
|
@ -16,10 +16,10 @@ pub fn pull() {
|
||||
.strip_prefix(path::repo_root()).unwrap().to_path_buf();
|
||||
let (folders, files) = get_diff(relative_p);
|
||||
|
||||
let ref_p = path::nextsync();
|
||||
let root = path::repo_root();
|
||||
|
||||
for folder in folders {
|
||||
let p = ref_p.clone().join(PathBuf::from(folder.relative_s.unwrap()));
|
||||
let p = root.clone().join(PathBuf::from(folder.relative_s.unwrap()));
|
||||
if !p.exists() {
|
||||
// create folder
|
||||
if let Err(err) = DirBuilder::new().recursive(true).create(p.clone()) {
|
||||
@ -27,9 +27,9 @@ pub fn pull() {
|
||||
}
|
||||
|
||||
// add tree
|
||||
let path_folder = p.strip_prefix(ref_p.clone()).unwrap();
|
||||
let path_folder = p.strip_prefix(root.clone()).unwrap();
|
||||
let lastmodified = folder.lastmodified.unwrap().timestamp_millis();
|
||||
if let Err(err) = Tree::from_path(path_folder.clone()).create(&lastmodified.to_string(), false) {
|
||||
if let Err(err) = Tree::from_path(path_folder).create(&lastmodified.to_string(), false) {
|
||||
eprintln!("err: saving ref of {} ({})", path_folder.display(), err);
|
||||
}
|
||||
}
|
||||
@ -39,13 +39,11 @@ pub fn pull() {
|
||||
.set_api_props(get_api_props())
|
||||
.set_files(files)
|
||||
.should_log()
|
||||
.download(ref_p.clone(), Some(&update_blob));
|
||||
.download(root, Some(&update_blob));
|
||||
// todo look if need to download or update
|
||||
}
|
||||
|
||||
fn update_blob(obj: ObjProps) {
|
||||
// todo update blob
|
||||
return;
|
||||
let relative_s = &obj.clone().relative_s.unwrap();
|
||||
let relative_p = PathBuf::from(&relative_s);
|
||||
let lastmodified = obj.clone().lastmodified.unwrap().timestamp_millis();
|
||||
|
@ -39,11 +39,9 @@ pub fn push() {
|
||||
let mut whitelist: Option<PathBuf> = None;
|
||||
|
||||
for obj in staged_objs {
|
||||
dbg!(obj.clone());
|
||||
if obj.otype == String::from("tree") {
|
||||
let push_factory = PushFactory.new_dir(obj.clone());
|
||||
let res = push_factory.can_push(&mut whitelist);
|
||||
dbg!(&res);
|
||||
match res {
|
||||
PushState::Valid => {
|
||||
match push_factory.push() {
|
||||
|
@ -24,7 +24,7 @@ pub fn remote_diff() {
|
||||
|
||||
pub fn get_diff(path: PathBuf) -> (Vec<ObjProps>, Vec<ObjProps>) {
|
||||
|
||||
let depth = "2"; // todo opti
|
||||
let depth = "6"; // todo opti
|
||||
let api_props = get_api_props();
|
||||
|
||||
enumerate_remote(
|
||||
@ -55,6 +55,7 @@ fn req(api_props: &ApiProps, depth: &str, relative_s: &str) -> Result<Vec<ObjPro
|
||||
.set_request(relative_s, &api_props)
|
||||
.set_depth(depth)
|
||||
.gethref()
|
||||
.getcontentlength() // todo opti
|
||||
.getlastmodified()
|
||||
.send_req_multiple()
|
||||
}
|
||||
|
@ -93,6 +93,7 @@ impl Downloader {
|
||||
let mut total_size = 0;
|
||||
let nb_objs = self.files.len();
|
||||
|
||||
// set the full size of the download
|
||||
self.files
|
||||
.iter()
|
||||
.for_each(|f|
|
||||
@ -111,11 +112,7 @@ impl Downloader {
|
||||
|
||||
let should_use_stream = {
|
||||
if let Some(size) = file.contentlength {
|
||||
if size > SIZE_TO_STREAM {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
size > SIZE_TO_STREAM
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
@ -111,6 +111,4 @@ impl Tree {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
// create
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ pub fn enumerate_remote(
|
||||
let mut deleted: Vec<PathBuf> = vec![];
|
||||
let mut files: Vec<ObjProps> = vec![];
|
||||
let mut objs_hashmap: HashMap<String, Vec<String>> = HashMap::new();
|
||||
|
||||
objs_hashmap.insert(
|
||||
options.relative_s.clone().unwrap_or(String::new()),
|
||||
Vec::new());
|
||||
@ -53,7 +54,11 @@ pub fn enumerate_remote(
|
||||
};
|
||||
|
||||
// separate folders and files in response
|
||||
let d = options.depth.clone().unwrap_or("0".to_owned()).parse::<u16>().unwrap();
|
||||
let d = options.depth.clone()
|
||||
.unwrap_or("0".to_owned())
|
||||
.parse::<u16>()
|
||||
.unwrap();
|
||||
|
||||
// first element is not used as it is the fetched folder
|
||||
if let Some(should_skip_fct) = should_skip.clone() {
|
||||
iter_with_skip_fct(
|
||||
@ -82,6 +87,7 @@ pub fn enumerate_remote(
|
||||
&mut all_folders);
|
||||
}
|
||||
}
|
||||
|
||||
// go through all folders not checked for deletion before
|
||||
// as they were empty
|
||||
if let Some(_) = should_skip.clone() {
|
||||
@ -90,18 +96,13 @@ pub fn enumerate_remote(
|
||||
objs_hashmap.remove(&key);
|
||||
}
|
||||
}
|
||||
dbg!(deleted);
|
||||
dbg!(objs_hashmap);
|
||||
|
||||
(all_folders, files)
|
||||
}
|
||||
|
||||
fn calc_depth(obj: &ObjProps) -> u16 {
|
||||
calc_depth_string(obj.relative_s.clone().unwrap_or(String::new()))
|
||||
}
|
||||
|
||||
fn calc_depth_string(s: String) -> u16 {
|
||||
s.split("/").count() as u16
|
||||
let path = obj.relative_s.clone().unwrap_or(String::new());
|
||||
path.split("/").count() as u16
|
||||
}
|
||||
|
||||
fn iter_with_skip_fct(
|
||||
@ -121,7 +122,6 @@ fn iter_with_skip_fct(
|
||||
let current_depth = calc_depth(object);
|
||||
|
||||
if object.is_dir() {
|
||||
|
||||
// add folder to parent folder only if exists
|
||||
let mut r_path = PathBuf::from(object.relative_s.clone().unwrap());
|
||||
r_path.pop();
|
||||
|
@ -1,9 +1,9 @@
|
||||
mod utils;
|
||||
use utils::{utils::*, status_utils::*, server::ServerTest, client::ClientTest};
|
||||
use utils::{utils::*, server::ServerTest, client::ClientTest};
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod push_tests {
|
||||
mod pull_tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
@ -23,4 +23,23 @@ mod push_tests {
|
||||
server.clean();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn simple_pull_directory() {
|
||||
let id = get_random_test_id();
|
||||
let mut server = ServerTest::new(id.clone());
|
||||
server.init();
|
||||
let mut client = ClientTest::new(id).init();
|
||||
|
||||
let _ = server.add_dir("dir");
|
||||
let _ = server.add_file("dir/file1", "foo");
|
||||
|
||||
client.run_cmd_ok("pull");
|
||||
|
||||
// tests
|
||||
assert!(client.has_file("dir/file1", "foo"));
|
||||
|
||||
client.clean();
|
||||
server.clean();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ pub fn has_files(full_path: PathBuf, file: &str, content: &str, test_id: String)
|
||||
{
|
||||
if !full_path.exists() {
|
||||
println!("id: {}", test_id.clone());
|
||||
eprintln!("File '{}' doesn't exists on the server", file);
|
||||
eprintln!("File '{}' doesn't exists", file);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -28,9 +28,9 @@ impl ServerTest {
|
||||
}
|
||||
|
||||
pub fn init(&mut self) -> &mut ServerTest{
|
||||
self.add_dir(self.test_id.clone());
|
||||
self.add_dir(&self.test_id.clone());
|
||||
self.volume = self.volume.join(self.test_id.clone());
|
||||
self.sync_test();
|
||||
self.sync_root();
|
||||
self
|
||||
}
|
||||
|
||||
@ -40,7 +40,7 @@ impl ServerTest {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_dir(&mut self, path: String) -> &mut ServerTest {
|
||||
pub fn add_dir(&mut self, path: &str) -> &mut ServerTest {
|
||||
let mut full_path = self.volume.clone();
|
||||
full_path.push(path);
|
||||
|
||||
@ -55,6 +55,11 @@ impl ServerTest {
|
||||
Err(e) => eprintln!("Error creating directory: {}", e),
|
||||
}
|
||||
|
||||
// do not sync test directory when creating it
|
||||
if !path.ends_with("_nextsync")
|
||||
{
|
||||
self.sync_test();
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
@ -73,6 +78,7 @@ impl ServerTest {
|
||||
full_path.push(path);
|
||||
|
||||
let _ = fs::remove_dir_all(&full_path);
|
||||
self.sync_test();
|
||||
self
|
||||
}
|
||||
|
||||
@ -89,17 +95,12 @@ impl ServerTest {
|
||||
// perform the occ files:scan command inside the nextcloud docker container
|
||||
|
||||
let nextcloud_docker = "master-nextcloud-1";
|
||||
let mut args = String::from("exec -ti --user www-data");
|
||||
args.push_str(nextcloud_docker);
|
||||
args.push_str("/var/www/html/occ files:scan --path=/");
|
||||
args.push_str(&self.user);
|
||||
args.push_str("files/");
|
||||
args.push_str(path);
|
||||
let args = format!("exec -t --user www-data {} /var/www/html/occ files:scan --path=/{}/files/{}", nextcloud_docker, &self.user, path);
|
||||
|
||||
let _output = Command::new("docker")
|
||||
.args(args.split(" "))
|
||||
.output()
|
||||
.expect("Could not execute nextsync command");
|
||||
.expect("Could not execute docker exec command");
|
||||
self
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user