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