test(pull): add test for pull
This commit is contained in:
parent
d5891a1a93
commit
7180647d26
26
tests/pull.rs
Normal file
26
tests/pull.rs
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
mod utils;
|
||||||
|
use utils::{utils::*, status_utils::*, server::ServerTest, client::ClientTest};
|
||||||
|
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod push_tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn simple_pull() {
|
||||||
|
let id = get_random_test_id();
|
||||||
|
let mut server = ServerTest::new(id.clone());
|
||||||
|
server.init();
|
||||||
|
let mut client = ClientTest::new(id).init();
|
||||||
|
|
||||||
|
let _ = server.add_file("file1", "foo");
|
||||||
|
client.run_cmd_ok("pull");
|
||||||
|
|
||||||
|
// tests
|
||||||
|
assert!(client.has_file("file1", "foo"));
|
||||||
|
|
||||||
|
client.clean();
|
||||||
|
server.clean();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -10,7 +10,8 @@ mod push_tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn simple_push() {
|
fn simple_push() {
|
||||||
let id = get_random_test_id();
|
let id = get_random_test_id();
|
||||||
let mut server = ServerTest::new(id.clone()).init();
|
let mut server = ServerTest::new(id.clone());
|
||||||
|
server.init();
|
||||||
let mut client = ClientTest::new(id).init();
|
let mut client = ClientTest::new(id).init();
|
||||||
|
|
||||||
let _ = client.add_file("file1", "foo");
|
let _ = client.add_file("file1", "foo");
|
||||||
@ -30,7 +31,8 @@ mod push_tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn push_update() {
|
fn push_update() {
|
||||||
let id = get_random_test_id();
|
let id = get_random_test_id();
|
||||||
let mut server = ServerTest::new(id.clone()).init();
|
let mut server = ServerTest::new(id.clone());
|
||||||
|
server.init();
|
||||||
let mut client = ClientTest::new(id).init();
|
let mut client = ClientTest::new(id).init();
|
||||||
|
|
||||||
// init content of file1
|
// init content of file1
|
||||||
@ -64,7 +66,8 @@ mod push_tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn push_dir_explicit() {
|
fn push_dir_explicit() {
|
||||||
let id = get_random_test_id();
|
let id = get_random_test_id();
|
||||||
let mut server = ServerTest::new(id.clone()).init();
|
let mut server = ServerTest::new(id.clone());
|
||||||
|
server.init();
|
||||||
let mut client = ClientTest::new(id).init();
|
let mut client = ClientTest::new(id).init();
|
||||||
|
|
||||||
let _ = client.add_dir("dir");
|
let _ = client.add_dir("dir");
|
||||||
@ -89,7 +92,8 @@ mod push_tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn push_dir_implicit() {
|
fn push_dir_implicit() {
|
||||||
let id = get_random_test_id();
|
let id = get_random_test_id();
|
||||||
let mut server = ServerTest::new(id.clone()).init();
|
let mut server = ServerTest::new(id.clone());
|
||||||
|
server.init();
|
||||||
let mut client = ClientTest::new(id).init();
|
let mut client = ClientTest::new(id).init();
|
||||||
|
|
||||||
let _ = client.add_dir("dir");
|
let _ = client.add_dir("dir");
|
||||||
@ -114,7 +118,8 @@ mod push_tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn push_all() {
|
fn push_all() {
|
||||||
let id = get_random_test_id();
|
let id = get_random_test_id();
|
||||||
let mut server = ServerTest::new(id.clone()).init();
|
let mut server = ServerTest::new(id.clone());
|
||||||
|
server.init();
|
||||||
let mut client = ClientTest::new(id).init();
|
let mut client = ClientTest::new(id).init();
|
||||||
|
|
||||||
let _ = client.add_file("file1", "foo");
|
let _ = client.add_file("file1", "foo");
|
||||||
|
@ -9,3 +9,6 @@ pub mod utils;
|
|||||||
|
|
||||||
#[path = "utils/status_utils.rs"]
|
#[path = "utils/status_utils.rs"]
|
||||||
pub mod status_utils;
|
pub mod status_utils;
|
||||||
|
|
||||||
|
#[path = "utils/files_utils.rs"]
|
||||||
|
pub mod files_utils;
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
use std::str;
|
use std::str;
|
||||||
use std::process::{Command, Output};
|
use std::process::{Command, Output};
|
||||||
use std::fs::{self, File};
|
use std::fs::{self, File};
|
||||||
use std::io::Write;
|
use std::io::{Write, BufReader, BufRead};
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
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
|
||||||
@ -92,6 +94,12 @@ impl ClientTest {
|
|||||||
Ok(())
|
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)
|
/// 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>) {
|
pub fn get_status(&mut self) -> (Vec<String>, Vec<String>) {
|
||||||
let out = self.run_cmd("status");
|
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::process::Command;
|
||||||
use std::os::unix::fs::PermissionsExt;
|
use std::os::unix::fs::PermissionsExt;
|
||||||
use std::fs::{self, File, Permissions};
|
use std::fs::{self, File, Permissions};
|
||||||
use std::io::{BufReader, BufRead};
|
use std::io::{BufReader, BufRead, Write};
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use super::files_utils::has_files;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub struct ServerTest {
|
pub struct ServerTest {
|
||||||
user: String,
|
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.add_dir(self.test_id.clone());
|
||||||
self.volume = self.volume.join(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.remove_dir(self.test_id.clone());
|
||||||
self.sync_root()
|
self.sync_root();
|
||||||
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_dir(&mut self, path: String) -> &mut ServerTest {
|
pub fn add_dir(&mut self, path: String) -> &mut ServerTest {
|
||||||
@ -54,6 +58,16 @@ impl ServerTest {
|
|||||||
self
|
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 {
|
pub fn remove_dir(&mut self, path: String) -> &mut ServerTest {
|
||||||
let mut full_path = self.volume.clone();
|
let mut full_path = self.volume.clone();
|
||||||
full_path.push(path);
|
full_path.push(path);
|
||||||
@ -62,16 +76,16 @@ impl ServerTest {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sync_root(self) -> Self {
|
fn sync_root(&self) -> &Self {
|
||||||
self.sync("")
|
self.sync("")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sync_test(self) -> Self {
|
fn sync_test(&self) -> &Self {
|
||||||
let test_id = self.test_id.clone();
|
let test_id = self.test_id.clone();
|
||||||
self.sync(&test_id)
|
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
|
// perform the occ files:scan command inside the nextcloud docker container
|
||||||
|
|
||||||
let nextcloud_docker = "master-nextcloud-1";
|
let nextcloud_docker = "master-nextcloud-1";
|
||||||
@ -91,25 +105,7 @@ impl ServerTest {
|
|||||||
|
|
||||||
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 = self.volume.clone().join(file);
|
let full_path = self.volume.clone().join(file);
|
||||||
|
has_files(full_path, file, content, self.test_id.clone())
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user