feat(test): allow multiple tests
This commit is contained in:
parent
e67082b85a
commit
642c358737
@ -1,4 +1,5 @@
|
||||
use rand::{distributions::Alphanumeric, Rng};
|
||||
use std::env;
|
||||
|
||||
mod utils;
|
||||
use utils::{server::ServerTest, client::ClientTest};
|
||||
@ -34,4 +35,30 @@ mod push_tests {
|
||||
client.clean();
|
||||
server.clean();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn push_update() {
|
||||
let id = get_random_test_id();
|
||||
let mut server = ServerTest::new(id.clone()).init();
|
||||
let mut client = ClientTest::new(id).init();
|
||||
|
||||
// init content of file1
|
||||
let _ = client.add_file("file1", "foo");
|
||||
client.run_cmd_ok("add file1");
|
||||
client.run_cmd_ok("push");
|
||||
|
||||
// tests
|
||||
assert!(server.has_file("file1", "foo"));
|
||||
|
||||
// change content of file1
|
||||
let _ = client.add_file("file1", "bar");
|
||||
client.run_cmd_ok("add file1");
|
||||
client.run_cmd_ok("push");
|
||||
|
||||
// tests
|
||||
assert!(server.has_file("file1", "bar"));
|
||||
|
||||
client.clean();
|
||||
server.clean();
|
||||
}
|
||||
}
|
||||
|
@ -5,10 +5,10 @@ use std::env;
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub struct ClientTest {
|
||||
user: String,
|
||||
volume: String,
|
||||
test_id: String,
|
||||
exe_path: PathBuf,
|
||||
user: String, // the nextcloud user
|
||||
volume: String, // temp dir for the test
|
||||
test_id: String, // name of the test (e.g nextsync_rand)
|
||||
exe_path: PathBuf, // absolute path of nextsync executable
|
||||
}
|
||||
|
||||
impl ClientTest {
|
||||
@ -23,7 +23,7 @@ impl ClientTest {
|
||||
let mut exe_path = env::current_dir().unwrap();
|
||||
exe_path = exe_path.join("target/debug/nextsync");
|
||||
|
||||
let _ = env::set_current_dir(vol.clone());
|
||||
// let _ = env::set_current_dir(vol.clone());
|
||||
|
||||
// build the client
|
||||
ClientTest {
|
||||
@ -46,12 +46,17 @@ impl ClientTest {
|
||||
|
||||
// set token for request
|
||||
self.run_cmd_ok(&format!("credential add {} {}", self.user, self.user));
|
||||
|
||||
self
|
||||
|
||||
}
|
||||
|
||||
pub fn clean(self) -> Self {
|
||||
pub fn clean(mut self) -> Self {
|
||||
let _ = fs::remove_dir_all(&self.volume);
|
||||
|
||||
// set back the current dir
|
||||
self.exe_path.pop();
|
||||
dbg!(self.exe_path.clone());
|
||||
let _ = env::set_current_dir(self.exe_path.clone());
|
||||
self
|
||||
}
|
||||
|
||||
@ -68,6 +73,7 @@ impl ClientTest {
|
||||
|
||||
pub fn run_cmd(&mut self, args: &str) -> Output {
|
||||
let output = Command::new(self.exe_path.to_str().unwrap())
|
||||
.current_dir(self.volume.clone())
|
||||
.args(args.split(" "))
|
||||
.output()
|
||||
.expect("Could not execute nextsync command");
|
||||
|
@ -93,17 +93,21 @@ impl ServerTest {
|
||||
let full_path = self.volume.clone().join(file);
|
||||
|
||||
if !full_path.exists() {
|
||||
eprintln!("File '{}' does't exists", file);
|
||||
eprintln!("File '{}' does't exists on the server", file);
|
||||
return false;
|
||||
}
|
||||
|
||||
let file = File::open(full_path).unwrap();
|
||||
for line in BufReader::new(file).lines(){
|
||||
let f = File::open(full_path).unwrap();
|
||||
for line in BufReader::new(f).lines(){
|
||||
if let Ok(line) = line {
|
||||
if line != content {
|
||||
eprintln!("File '{}' is not equal, {} != {}", file, line, content);
|
||||
return false;
|
||||
}
|
||||
return line == content;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user