test(push): add push remove test
This commit is contained in:
parent
5e43800d6c
commit
1aa02a24af
@ -32,6 +32,7 @@ pub fn add(args: AddArgs) {
|
|||||||
let rules = nextsyncignore::get_rules();
|
let rules = nextsyncignore::get_rules();
|
||||||
|
|
||||||
for file in file_vec {
|
for file in file_vec {
|
||||||
|
dbg!(&file);
|
||||||
let f = match normalize_relative(file) {
|
let f = match normalize_relative(file) {
|
||||||
Ok(f) => f,
|
Ok(f) => f,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
|||||||
@ -39,7 +39,7 @@ fn collect_status_lines(client: &mut ClientTest) -> Vec<String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod push_tests {
|
mod add_tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@ -2,6 +2,14 @@
|
|||||||
mod utils;
|
mod utils;
|
||||||
use utils::{utils::*, status_utils::*, server::ServerTest, client::ClientTest};
|
use utils::{utils::*, status_utils::*, server::ServerTest, client::ClientTest};
|
||||||
|
|
||||||
|
fn init_test() -> (ClientTest, ServerTest) {
|
||||||
|
let id = get_random_test_id();
|
||||||
|
let mut server = ServerTest::new(id.clone());
|
||||||
|
server.init();
|
||||||
|
let client = ClientTest::new(id).init();
|
||||||
|
(client, server)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod push_tests {
|
mod push_tests {
|
||||||
@ -9,10 +17,7 @@ mod push_tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn simple_push() {
|
fn simple_push() {
|
||||||
let id = get_random_test_id();
|
let (mut client, mut server) = init_test();
|
||||||
let mut server = ServerTest::new(id.clone());
|
|
||||||
server.init();
|
|
||||||
let mut client = ClientTest::new(id).init();
|
|
||||||
|
|
||||||
let _ = client.add_file("file1", "foo");
|
let _ = client.add_file("file1", "foo");
|
||||||
client.run_cmd_ok("add file1");
|
client.run_cmd_ok("add file1");
|
||||||
@ -30,10 +35,7 @@ mod push_tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn push_update() {
|
fn push_update() {
|
||||||
let id = get_random_test_id();
|
let (mut client, mut server) = init_test();
|
||||||
let mut server = ServerTest::new(id.clone());
|
|
||||||
server.init();
|
|
||||||
let mut client = ClientTest::new(id).init();
|
|
||||||
|
|
||||||
// init content of file1
|
// init content of file1
|
||||||
let _ = client.add_file("file1", "foo");
|
let _ = client.add_file("file1", "foo");
|
||||||
@ -65,10 +67,7 @@ mod push_tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn push_dir_explicit() {
|
fn push_dir_explicit() {
|
||||||
let id = get_random_test_id();
|
let (mut client, mut server) = init_test();
|
||||||
let mut server = ServerTest::new(id.clone());
|
|
||||||
server.init();
|
|
||||||
let mut client = ClientTest::new(id).init();
|
|
||||||
|
|
||||||
let _ = client.add_dir("dir");
|
let _ = client.add_dir("dir");
|
||||||
let _ = client.add_file("dir/file2", "bar");
|
let _ = client.add_file("dir/file2", "bar");
|
||||||
@ -91,10 +90,7 @@ mod push_tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn push_dir_implicit() {
|
fn push_dir_implicit() {
|
||||||
let id = get_random_test_id();
|
let (mut client, mut server) = init_test();
|
||||||
let mut server = ServerTest::new(id.clone());
|
|
||||||
server.init();
|
|
||||||
let mut client = ClientTest::new(id).init();
|
|
||||||
|
|
||||||
let _ = client.add_dir("dir");
|
let _ = client.add_dir("dir");
|
||||||
let _ = client.add_file("dir/file2", "bar");
|
let _ = client.add_file("dir/file2", "bar");
|
||||||
@ -117,10 +113,7 @@ mod push_tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn push_all() {
|
fn push_all() {
|
||||||
let id = get_random_test_id();
|
let (mut client, mut server) = init_test();
|
||||||
let mut server = ServerTest::new(id.clone());
|
|
||||||
server.init();
|
|
||||||
let mut client = ClientTest::new(id).init();
|
|
||||||
|
|
||||||
let _ = client.add_file("file1", "foo");
|
let _ = client.add_file("file1", "foo");
|
||||||
let _ = client.add_dir("dir");
|
let _ = client.add_dir("dir");
|
||||||
@ -140,4 +133,32 @@ mod push_tests {
|
|||||||
client.clean();
|
client.clean();
|
||||||
server.clean();
|
server.clean();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn push_file_deletion() {
|
||||||
|
let (mut client, mut server) = init_test();
|
||||||
|
|
||||||
|
let _ = client.add_file("file1", "foo");
|
||||||
|
|
||||||
|
// push file1
|
||||||
|
client.run_cmd_ok("add file1");
|
||||||
|
client.run_cmd_ok("push");
|
||||||
|
|
||||||
|
// tests
|
||||||
|
assert!(server.has_file("file1", "foo"));
|
||||||
|
status_should_be_empty(&mut client);
|
||||||
|
|
||||||
|
// remove it
|
||||||
|
let _ = client.remove_file("file1");
|
||||||
|
client.run_cmd_ok("add file1");
|
||||||
|
dbg!(client.get_status());
|
||||||
|
client.run_cmd_ok("push");
|
||||||
|
|
||||||
|
// tests
|
||||||
|
assert!(server.has_not_file("file1"));
|
||||||
|
status_should_be_empty(&mut client);
|
||||||
|
|
||||||
|
client.clean();
|
||||||
|
server.clean();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,7 +11,7 @@ use super::files_utils::has_files;
|
|||||||
pub struct ClientTest {
|
pub struct ClientTest {
|
||||||
user: String, // the nextcloud user
|
user: String, // the nextcloud user
|
||||||
volume: String, // temp dir for the test
|
volume: String, // temp dir for the test
|
||||||
test_id: String, // name of the test (e.g nextsync_rand)
|
pub test_id: String, // name of the test (e.g nextsync_rand)
|
||||||
exe_path: PathBuf, // absolute path of nextsync executable
|
exe_path: PathBuf, // absolute path of nextsync executable
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,6 +96,15 @@ impl ClientTest {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn remove_file(&mut self, name: &str) -> std::io::Result<()> {
|
||||||
|
let mut path = self.volume.clone();
|
||||||
|
path.push_str("/");
|
||||||
|
path.push_str(name);
|
||||||
|
|
||||||
|
fs::remove_file(name)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn has_file(&mut self, file: &str, content: &str) -> bool {
|
pub fn has_file(&mut self, file: &str, content: &str) -> bool {
|
||||||
let full_path = PathBuf::from(self.volume.clone()).join(file);
|
let full_path = PathBuf::from(self.volume.clone()).join(file);
|
||||||
|
|
||||||
|
|||||||
@ -24,3 +24,15 @@ pub fn has_files(full_path: PathBuf, file: &str, content: &str, test_id: String)
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
pub fn has_not_file(full_path: PathBuf, file: &str, test_id: String) -> bool
|
||||||
|
{
|
||||||
|
if full_path.exists() {
|
||||||
|
println!("id: {}", test_id.clone());
|
||||||
|
eprintln!("File '{}' exists but it shouldn't", file);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|||||||
@ -5,13 +5,13 @@ use std::io::Write;
|
|||||||
use std::env;
|
use std::env;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use super::files_utils::has_files;
|
use super::files_utils::{self, has_files};
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub struct ServerTest {
|
pub struct ServerTest {
|
||||||
user: String,
|
user: String,
|
||||||
volume: PathBuf,
|
volume: PathBuf,
|
||||||
test_id: String
|
pub test_id: String
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@ -108,5 +108,10 @@ impl ServerTest {
|
|||||||
let full_path = self.volume.clone().join(file);
|
let full_path = self.volume.clone().join(file);
|
||||||
has_files(full_path, file, content, self.test_id.clone())
|
has_files(full_path, file, content, self.test_id.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn has_not_file(&mut self, file: &str) -> bool {
|
||||||
|
let full_path = self.volume.clone().join(file);
|
||||||
|
files_utils::has_not_file(full_path, file, self.test_id.clone())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
use super::client::ClientTest;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub fn lines_should_not_contains(lines: Vec<String>, str: &str) {
|
pub fn lines_should_not_contains(lines: Vec<String>, str: &str) {
|
||||||
@ -8,3 +9,19 @@ pub fn lines_should_not_contains(lines: Vec<String>, str: &str) {
|
|||||||
assert!(line.find(str).is_none());
|
assert!(line.find(str).is_none());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
pub fn status_should_be_empty(client: &mut ClientTest) {
|
||||||
|
let (staged, not_staged) = client.get_status();
|
||||||
|
if staged.len() != 0 {
|
||||||
|
eprintln!("id: {}", client.test_id.clone());
|
||||||
|
eprintln!("Staged should be empty but has '{}'", staged.len());
|
||||||
|
assert!(staged.len() == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if staged.len() != 0 {
|
||||||
|
eprintln!("id: {}", client.test_id.clone());
|
||||||
|
eprintln!("Not Staged should be empty but has '{}'", not_staged.len());
|
||||||
|
assert!(not_staged.len() == 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user