tests(add): introduce basics tests for add
This commit is contained in:
parent
baeef1a33a
commit
e66dc8d408
49
tests/add_test.rs
Normal file
49
tests/add_test.rs
Normal file
@ -0,0 +1,49 @@
|
||||
mod common;
|
||||
|
||||
use common::client::ClientTest;
|
||||
use nextsync::store::indexer::Indexer;
|
||||
use nextsync::commands::status::{get_obj_changes, StatusArgs};
|
||||
use nextsync::config::config::Config;
|
||||
use std::io;
|
||||
use std::path::PathBuf;
|
||||
|
||||
const DEFAULT_STATUS_ARG: StatusArgs = StatusArgs { nostyle: false };
|
||||
|
||||
fn indexed_expected(indexer: &Indexer, expected: Vec<&str>) {
|
||||
let objs = indexer.get_indexed_objs();
|
||||
|
||||
assert_eq!(objs.len(), expected.len());
|
||||
|
||||
for obj in expected {
|
||||
assert!(objs
|
||||
.iter()
|
||||
.position(|e| { e.path == PathBuf::from(obj) })
|
||||
.is_some());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_ignored_file() -> io::Result<()> {
|
||||
let mut client = ClientTest::new("add__simple_file").init();
|
||||
client.add_ignore_rule("foo");
|
||||
client.add_file("foo", "foo")?;
|
||||
|
||||
let mut indexer = Indexer::new(client.get_config().get_root_unsafe());
|
||||
|
||||
client.exec_ok("add foo");
|
||||
let _ = indexer.load();
|
||||
indexed_expected(&indexer, vec![]);
|
||||
|
||||
client.exec_ok("add foo -f");
|
||||
let _ = indexer.load();
|
||||
indexed_expected(&indexer, vec!["foo"]);
|
||||
|
||||
client.ok()
|
||||
}
|
||||
|
||||
// add double globbing
|
||||
// add all
|
||||
// add folders
|
||||
// add part of folders
|
||||
// add all folder
|
||||
// add automatic ignored if is tracked
|
@ -1,4 +1,5 @@
|
||||
use nextsync::config::config::Config;
|
||||
use std::fs::OpenOptions;
|
||||
use rand::{distributions::Alphanumeric, Rng};
|
||||
use std::env;
|
||||
use std::fs::{self, File};
|
||||
@ -125,6 +126,18 @@ impl ClientTest {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn add_ignore_rule(&self, rule: &str) {
|
||||
let mut nsignore_path = self.volume.clone();
|
||||
nsignore_path.push_str("/.nsignore");
|
||||
let mut file = OpenOptions::new()
|
||||
.write(true)
|
||||
.create(true)
|
||||
.append(true)
|
||||
.open(nsignore_path).unwrap();
|
||||
|
||||
let _ = writeln!(file, "{rule}").unwrap();
|
||||
}
|
||||
|
||||
// pub fn has_file(&mut self, file: &str, content: &str) -> bool {
|
||||
// let full_path = PathBuf::from(self.volume.clone()).join(file);
|
||||
|
||||
|
4
tests/reset_test.rs
Normal file
4
tests/reset_test.rs
Normal file
@ -0,0 +1,4 @@
|
||||
// reset all
|
||||
// reset file
|
||||
// reset folder
|
||||
// reset unknown
|
@ -8,7 +8,7 @@ use std::path::PathBuf;
|
||||
|
||||
const DEFAULT_STATUS_ARG: StatusArgs = StatusArgs { nostyle: false };
|
||||
|
||||
fn status_exepected(config: &Config, staged: Vec<&str>, not_staged: Vec<&str>) {
|
||||
fn status_expected(config: &Config, staged: Vec<&str>, not_staged: Vec<&str>) {
|
||||
let res = get_obj_changes(&DEFAULT_STATUS_ARG, config);
|
||||
|
||||
assert_eq!(res.staged.len(), staged.len());
|
||||
@ -36,16 +36,15 @@ fn simple_file() -> io::Result<()> {
|
||||
let mut client = ClientTest::new("status__simple_file").init();
|
||||
|
||||
client.add_file("foo", "foo")?;
|
||||
status_exepected(&client.get_config(), vec![], vec!["foo"]);
|
||||
status_expected(&client.get_config(), vec![], vec!["foo"]);
|
||||
|
||||
client.exec_ok("add foo");
|
||||
status_exepected(&client.get_config(), vec!["foo"], vec![]);
|
||||
status_expected(&client.get_config(), vec!["foo"], vec![]);
|
||||
|
||||
client.ok()
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn all_folder() -> io::Result<()> {
|
||||
let mut client = ClientTest::new("status__all_folder").init();
|
||||
|
||||
@ -53,10 +52,10 @@ fn all_folder() -> io::Result<()> {
|
||||
client.add_file("dir/foo", "foo")?;
|
||||
client.add_file("dir/bar", "bar")?;
|
||||
client.add_file("foo", "foo")?;
|
||||
status_exepected(&client.get_config(), vec![], vec!["foo", "dir"]);
|
||||
status_expected(&client.get_config(), vec![], vec!["foo", "dir"]);
|
||||
|
||||
client.exec_ok("add dir");
|
||||
status_exepected(&client.get_config(), vec!["dir"], vec!["foo"]);
|
||||
status_expected(&client.get_config(), vec!["dir/foo", "dir/bar"], vec!["foo"]);
|
||||
|
||||
client.ok()
|
||||
}
|
||||
@ -70,10 +69,10 @@ fn all_folder_current() -> io::Result<()> {
|
||||
client.add_file("dir/foo", "foo")?;
|
||||
client.add_file("dir/bar", "bar")?;
|
||||
client.add_file("foor", "foor")?;
|
||||
status_exepected(&client.get_config(), vec![], vec!["foor", "dir"]);
|
||||
status_expected(&client.get_config(), vec![], vec!["foor", "dir"]);
|
||||
|
||||
client.exec_ok("add dir");
|
||||
status_exepected(
|
||||
status_expected(
|
||||
&Config::from(Some(&String::from("./dir"))),
|
||||
vec!["foor", "bar"],
|
||||
vec!["../foo"],
|
||||
@ -90,10 +89,10 @@ fn part_of_folder() -> io::Result<()> {
|
||||
client.add_file("dir/foo", "foo")?;
|
||||
client.add_file("dir/bar", "bar")?;
|
||||
client.add_file("foor", "foor")?;
|
||||
status_exepected(&client.get_config(), vec![], vec!["foor", "dir"]);
|
||||
status_expected(&client.get_config(), vec![], vec!["foor", "dir"]);
|
||||
|
||||
client.exec_ok("add dir/foo");
|
||||
status_exepected(
|
||||
status_expected(
|
||||
&client.get_config(),
|
||||
vec!["dir/foo"],
|
||||
vec!["foor", "dir/bar"],
|
||||
|
Loading…
Reference in New Issue
Block a user