test(push): add push remove test
This commit is contained in:
@@ -11,7 +11,7 @@ use super::files_utils::has_files;
|
||||
pub struct ClientTest {
|
||||
user: String, // the nextcloud user
|
||||
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
|
||||
}
|
||||
|
||||
@@ -96,6 +96,15 @@ impl ClientTest {
|
||||
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 {
|
||||
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;
|
||||
}
|
||||
|
||||
#[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::path::PathBuf;
|
||||
|
||||
use super::files_utils::has_files;
|
||||
use super::files_utils::{self, has_files};
|
||||
|
||||
#[cfg(test)]
|
||||
pub struct ServerTest {
|
||||
user: String,
|
||||
volume: PathBuf,
|
||||
test_id: String
|
||||
pub test_id: String
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -108,5 +108,10 @@ impl ServerTest {
|
||||
let full_path = self.volume.clone().join(file);
|
||||
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)]
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
#[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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user