diff --git a/tests/add.rs b/tests/add.rs index a9fa634..bae10c9 100644 --- a/tests/add.rs +++ b/tests/add.rs @@ -3,17 +3,18 @@ use std::str; mod utils; use utils::{utils::*, client::ClientTest}; -fn line_should_contains(line: &str, str: &str) { +fn line_should_contains(lines: &Vec, nb: usize, str: &str) { - if line.find(str).is_none() + if lines[nb].find(str).is_none() { - eprintln!("'{}' not found in '{}'", str, line); + eprintln!("'{}' not found in '{}'", str, lines[nb]); + dbg!(lines); } - assert!(line.find(str).is_some()); + assert!(lines[nb].find(str).is_some()); } -fn lines_should_not_contains(lines: Vec<&str>, str: &str) { +fn lines_should_not_contains(lines: Vec, str: &str) { for line in lines { if line.find("Changes not staged for push").is_some() { @@ -28,6 +29,16 @@ fn lines_should_not_contains(lines: Vec<&str>, str: &str) { } +fn collect_status_lines(client: &mut ClientTest) -> Vec { + let out = client.run_cmd("status"); + + str::from_utf8(&out.stdout) + .unwrap() + .split("\n") + .map(|s| s.to_owned()) + .collect() +} + #[cfg(test)] mod push_tests { use super::*; @@ -40,13 +51,10 @@ mod push_tests { let _ = client.add_file("file1", "foo"); client.run_cmd_ok("add file1"); - let out = client.run_cmd("status"); - let lines: Vec<&str> = str::from_utf8(&out.stdout) - .unwrap() - .split("\n") - .collect(); + let lines = collect_status_lines(&mut client); - line_should_contains(lines[2], "file1"); + // test + line_should_contains(&lines, 2, "file1"); client.clean(); } @@ -59,15 +67,32 @@ mod push_tests { let _ = client.add_file("file1", "foo"); client.run_cmd_ok("add .nextsync -f"); - let out = client.run_cmd("status"); - let lines: Vec<&str> = str::from_utf8(&out.stdout) - .unwrap() - .split("\n") - .collect(); + let lines = collect_status_lines(&mut client); + // test lines_should_not_contains(lines, ".nextsync"); client.clean(); } + #[test] + fn add_dir_implicit() { + let id = get_random_test_id(); + let mut client = ClientTest::new(id).init(); + + let _ = client.add_dir("dir"); + let _ = client.add_file("dir/file1", "foo"); + + // adding the file should add the dir + client.run_cmd_ok("add dir/file1"); + + let lines = collect_status_lines(&mut client); + + // tests + line_should_contains(&lines, 2, "dir"); + line_should_contains(&lines, 3, "dir/file1"); + + client.clean(); + } + } diff --git a/tests/push.rs b/tests/push.rs index c816d94..cdda442 100644 --- a/tests/push.rs +++ b/tests/push.rs @@ -1,4 +1,3 @@ -use rand::{distributions::Alphanumeric, Rng}; mod utils; use utils::{utils::*, server::ServerTest, client::ClientTest}; @@ -81,7 +80,7 @@ mod push_tests { let _ = client.add_file("dir/file2", "bar"); // push dir and file2 - client.run_cmd_ok("add file2"); + client.run_cmd_ok("add dir/file2"); client.run_cmd_ok("push"); // tests diff --git a/tests/utils/client.rs b/tests/utils/client.rs index 89acad1..333cf1e 100644 --- a/tests/utils/client.rs +++ b/tests/utils/client.rs @@ -13,7 +13,6 @@ pub struct ClientTest { impl ClientTest { pub fn new(id: String) -> Self { - // create a directory in /tmp with the given id let mut vol = String::from("/tmp/"); vol.push_str(&id); @@ -56,6 +55,7 @@ impl ClientTest { pub fn run_cmd_ok(&mut self, args: &str) -> Output { let output = self.run_cmd(args); if !output.status.success() { + println!("id: {}", self.test_id.clone()); println!("Failed to execute: '{}'", args); println!("stderr: {}", String::from_utf8_lossy(&output.stderr)); println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); diff --git a/tests/utils/server.rs b/tests/utils/server.rs index 71600e4..1af3ed5 100644 --- a/tests/utils/server.rs +++ b/tests/utils/server.rs @@ -93,6 +93,7 @@ impl ServerTest { let full_path = self.volume.clone().join(file); if !full_path.exists() { + println!("id: {}", self.test_id.clone()); eprintln!("File '{}' doesn't exists on the server", file); return false; } @@ -101,6 +102,7 @@ impl ServerTest { for line in BufReader::new(f).lines(){ if let Ok(line) = line { if line != content { + println!("id: {}", self.test_id.clone()); eprintln!("File '{}' is not equal, {} != {}", file, line, content); return false; }