test(add): first tests
This commit is contained in:
parent
6b7a82bec6
commit
fe628ffc9f
73
tests/add.rs
Normal file
73
tests/add.rs
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
use std::str;
|
||||||
|
|
||||||
|
mod utils;
|
||||||
|
use utils::{utils::*, client::ClientTest};
|
||||||
|
|
||||||
|
fn line_should_contains(line: &str, str: &str) {
|
||||||
|
|
||||||
|
if line.find(str).is_none()
|
||||||
|
{
|
||||||
|
eprintln!("'{}' not found in '{}'", str, line);
|
||||||
|
}
|
||||||
|
|
||||||
|
assert!(line.find(str).is_some());
|
||||||
|
}
|
||||||
|
|
||||||
|
fn lines_should_not_contains(lines: Vec<&str>, str: &str) {
|
||||||
|
|
||||||
|
for line in lines {
|
||||||
|
if line.find("Changes not staged for push").is_some() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if line.find(str).is_some() {
|
||||||
|
eprintln!("'{}' found in '{}'", str, line);
|
||||||
|
}
|
||||||
|
assert!(line.find(str).is_none());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod push_tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn simple_add() {
|
||||||
|
let id = get_random_test_id();
|
||||||
|
let mut client = ClientTest::new(id).init();
|
||||||
|
|
||||||
|
let _ = client.add_file("file1", "foo");
|
||||||
|
client.run_cmd_ok("add file1");
|
||||||
|
|
||||||
|
let out = client.run_cmd("status");
|
||||||
|
let lines: Vec<&str> = str::from_utf8(&out.stdout)
|
||||||
|
.unwrap()
|
||||||
|
.split("\n")
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
line_should_contains(lines[2], "file1");
|
||||||
|
|
||||||
|
client.clean();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn add_config_file() {
|
||||||
|
let id = get_random_test_id();
|
||||||
|
let mut client = ClientTest::new(id).init();
|
||||||
|
|
||||||
|
let _ = client.add_file("file1", "foo");
|
||||||
|
client.run_cmd_ok("add .nextsync -f");
|
||||||
|
|
||||||
|
let out = client.run_cmd("status");
|
||||||
|
let lines: Vec<&str> = str::from_utf8(&out.stdout)
|
||||||
|
.unwrap()
|
||||||
|
.split("\n")
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
lines_should_not_contains(lines, ".nextsync");
|
||||||
|
|
||||||
|
client.clean();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,19 +1,9 @@
|
|||||||
use rand::{distributions::Alphanumeric, Rng};
|
use rand::{distributions::Alphanumeric, Rng};
|
||||||
|
|
||||||
mod utils;
|
mod utils;
|
||||||
use utils::{server::ServerTest, client::ClientTest};
|
use utils::{utils::*, server::ServerTest, client::ClientTest};
|
||||||
|
|
||||||
|
|
||||||
fn get_random_test_id() -> String {
|
|
||||||
let mut id: String = rand::thread_rng()
|
|
||||||
.sample_iter(&Alphanumeric)
|
|
||||||
.take(7)
|
|
||||||
.map(char::from)
|
|
||||||
.collect();
|
|
||||||
id.push_str("_nextsync");
|
|
||||||
id.to_owned()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod push_tests {
|
mod push_tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
@ -62,7 +52,27 @@ mod push_tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn push_dir() {
|
fn push_dir_explicit() {
|
||||||
|
let id = get_random_test_id();
|
||||||
|
let mut server = ServerTest::new(id.clone()).init();
|
||||||
|
let mut client = ClientTest::new(id).init();
|
||||||
|
|
||||||
|
let _ = client.add_dir("dir");
|
||||||
|
let _ = client.add_file("dir/file2", "bar");
|
||||||
|
|
||||||
|
// push dir and file2
|
||||||
|
client.run_cmd_ok("add dir");
|
||||||
|
client.run_cmd_ok("push");
|
||||||
|
|
||||||
|
// tests
|
||||||
|
assert!(server.has_file("dir/file2", "bar"));
|
||||||
|
|
||||||
|
client.clean();
|
||||||
|
server.clean();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
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()).init();
|
||||||
let mut client = ClientTest::new(id).init();
|
let mut client = ClientTest::new(id).init();
|
||||||
|
@ -3,3 +3,6 @@ pub mod server;
|
|||||||
|
|
||||||
#[path = "utils/client.rs"]
|
#[path = "utils/client.rs"]
|
||||||
pub mod client;
|
pub mod client;
|
||||||
|
|
||||||
|
#[path = "utils/utils.rs"]
|
||||||
|
pub mod utils;
|
||||||
|
11
tests/utils/utils.rs
Normal file
11
tests/utils/utils.rs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
use rand::{distributions::Alphanumeric, Rng};
|
||||||
|
|
||||||
|
pub fn get_random_test_id() -> String {
|
||||||
|
let mut id: String = rand::thread_rng()
|
||||||
|
.sample_iter(&Alphanumeric)
|
||||||
|
.take(7)
|
||||||
|
.map(char::from)
|
||||||
|
.collect();
|
||||||
|
id.push_str("_nextsync");
|
||||||
|
id.to_owned()
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user