diff --git a/tests/add.rs b/tests/add.rs new file mode 100644 index 0000000..a9fa634 --- /dev/null +++ b/tests/add.rs @@ -0,0 +1,73 @@ +use std::str; + +mod utils; +use utils::{utils::*, client::ClientTest}; + +fn line_should_contains(line: &str, str: &str) { + + if line.find(str).is_none() + { + eprintln!("'{}' not found in '{}'", str, line); + } + + assert!(line.find(str).is_some()); +} + +fn lines_should_not_contains(lines: Vec<&str>, str: &str) { + + for line in lines { + if line.find("Changes not staged for push").is_some() { + return; + } + + if line.find(str).is_some() { + eprintln!("'{}' found in '{}'", str, line); + } + assert!(line.find(str).is_none()); + } + +} + +#[cfg(test)] +mod push_tests { + use super::*; + + #[test] + fn simple_add() { + let id = get_random_test_id(); + let mut client = ClientTest::new(id).init(); + + 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(); + + line_should_contains(lines[2], "file1"); + + client.clean(); + } + + #[test] + fn add_config_file() { + let id = get_random_test_id(); + let mut client = ClientTest::new(id).init(); + + 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(); + + lines_should_not_contains(lines, ".nextsync"); + + client.clean(); + } + +} diff --git a/tests/push.rs b/tests/push.rs index 8462440..c816d94 100644 --- a/tests/push.rs +++ b/tests/push.rs @@ -1,19 +1,9 @@ use rand::{distributions::Alphanumeric, Rng}; mod utils; -use utils::{server::ServerTest, client::ClientTest}; +use utils::{utils::*, server::ServerTest, client::ClientTest}; -fn get_random_test_id() -> String { - let mut id: String = rand::thread_rng() - .sample_iter(&Alphanumeric) - .take(7) - .map(char::from) - .collect(); - id.push_str("_nextsync"); - id.to_owned() -} - #[cfg(test)] mod push_tests { use super::*; @@ -62,7 +52,27 @@ mod push_tests { } #[test] - fn push_dir() { + fn push_dir_explicit() { + 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 dir"); + client.run_cmd_ok("push"); + + // tests + assert!(server.has_file("dir/file2", "bar")); + + client.clean(); + server.clean(); + } + + #[test] + fn push_dir_implicit() { let id = get_random_test_id(); let mut server = ServerTest::new(id.clone()).init(); let mut client = ClientTest::new(id).init(); diff --git a/tests/utils.rs b/tests/utils.rs index 48e0577..29dafbb 100644 --- a/tests/utils.rs +++ b/tests/utils.rs @@ -3,3 +3,6 @@ pub mod server; #[path = "utils/client.rs"] pub mod client; + +#[path = "utils/utils.rs"] +pub mod utils; diff --git a/tests/utils/utils.rs b/tests/utils/utils.rs new file mode 100644 index 0000000..80b931d --- /dev/null +++ b/tests/utils/utils.rs @@ -0,0 +1,11 @@ +use rand::{distributions::Alphanumeric, Rng}; + +pub fn get_random_test_id() -> String { + let mut id: String = rand::thread_rng() + .sample_iter(&Alphanumeric) + .take(7) + .map(char::from) + .collect(); + id.push_str("_nextsync"); + id.to_owned() +}