test(pull): add test for pull
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
use std::str;
|
||||
use std::process::{Command, Output};
|
||||
use std::fs::{self, File};
|
||||
use std::io::Write;
|
||||
use std::io::{Write, BufReader, BufRead};
|
||||
use std::env;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use super::files_utils::has_files;
|
||||
|
||||
pub struct ClientTest {
|
||||
user: String, // the nextcloud user
|
||||
volume: String, // temp dir for the test
|
||||
@@ -92,6 +94,12 @@ impl ClientTest {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn has_file(&mut self, file: &str, content: &str) -> bool {
|
||||
let full_path = PathBuf::from(self.volume.clone()).join(file);
|
||||
|
||||
has_files(full_path, file, content, self.test_id.clone())
|
||||
}
|
||||
|
||||
/// get the files given by the status command in two vector (staged and not staged)
|
||||
pub fn get_status(&mut self) -> (Vec<String>, Vec<String>) {
|
||||
let out = self.run_cmd("status");
|
||||
|
||||
25
tests/utils/files_utils.rs
Normal file
25
tests/utils/files_utils.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
use std::io::{BufReader, BufRead, Write};
|
||||
use std::fs::{File};
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub fn has_files(full_path: PathBuf, file: &str, content: &str, test_id: String) -> bool
|
||||
{
|
||||
if !full_path.exists() {
|
||||
println!("id: {}", test_id.clone());
|
||||
eprintln!("File '{}' doesn't exists on the server", file);
|
||||
return false;
|
||||
}
|
||||
|
||||
let f = File::open(full_path).unwrap();
|
||||
for line in BufReader::new(f).lines(){
|
||||
if let Ok(line) = line {
|
||||
if line != content {
|
||||
println!("id: {}", test_id);
|
||||
eprintln!("File '{}' is not equal, {} != {}", file, line, content);
|
||||
return false;
|
||||
}
|
||||
return line == content;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
use std::process::Command;
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
use std::fs::{self, File, Permissions};
|
||||
use std::io::{BufReader, BufRead};
|
||||
use std::io::{BufReader, BufRead, Write};
|
||||
use std::env;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use super::files_utils::has_files;
|
||||
|
||||
#[cfg(test)]
|
||||
pub struct ServerTest {
|
||||
user: String,
|
||||
@@ -25,15 +27,17 @@ impl ServerTest {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn init(mut self) -> Self {
|
||||
pub fn init(&mut self) -> &mut ServerTest{
|
||||
self.add_dir(self.test_id.clone());
|
||||
self.volume = self.volume.join(self.test_id.clone());
|
||||
self.sync_test()
|
||||
self.sync_test();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn clean(mut self) -> Self {
|
||||
pub fn clean(&mut self) -> &mut ServerTest{
|
||||
self.remove_dir(self.test_id.clone());
|
||||
self.sync_root()
|
||||
self.sync_root();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_dir(&mut self, path: String) -> &mut ServerTest {
|
||||
@@ -54,6 +58,16 @@ impl ServerTest {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_file(&mut self, name: &str, content: &str) -> std::io::Result<()> {
|
||||
let mut full_path = self.volume.clone();
|
||||
full_path.push(name);
|
||||
|
||||
let mut file = File::create(full_path)?;
|
||||
file.write_all(content.as_bytes())?;
|
||||
self.sync_test();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn remove_dir(&mut self, path: String) -> &mut ServerTest {
|
||||
let mut full_path = self.volume.clone();
|
||||
full_path.push(path);
|
||||
@@ -62,16 +76,16 @@ impl ServerTest {
|
||||
self
|
||||
}
|
||||
|
||||
fn sync_root(self) -> Self {
|
||||
fn sync_root(&self) -> &Self {
|
||||
self.sync("")
|
||||
}
|
||||
|
||||
fn sync_test(self) -> Self {
|
||||
fn sync_test(&self) -> &Self {
|
||||
let test_id = self.test_id.clone();
|
||||
self.sync(&test_id)
|
||||
}
|
||||
|
||||
fn sync(self, path: &str) -> Self {
|
||||
fn sync(&self, path: &str) -> &Self {
|
||||
// perform the occ files:scan command inside the nextcloud docker container
|
||||
|
||||
let nextcloud_docker = "master-nextcloud-1";
|
||||
@@ -91,25 +105,7 @@ impl ServerTest {
|
||||
|
||||
pub fn has_file(&mut self, file: &str, content: &str) -> bool {
|
||||
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;
|
||||
}
|
||||
|
||||
let f = File::open(full_path).unwrap();
|
||||
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;
|
||||
}
|
||||
return line == content;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
has_files(full_path, file, content, self.test_id.clone())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user