feat(push): save objects

This commit is contained in:
grimhilt
2024-09-12 23:22:20 +02:00
parent 8f636b4bf7
commit a69a71d843
16 changed files with 230 additions and 68 deletions

View File

@@ -1,7 +1,7 @@
mod common;
use common::client::ClientTest;
use nextsync::store::indexer::Indexer;
use nextsync::store::{structs::to_obj_path, indexer::Indexer};
use nextsync::commands::status::{get_obj_changes, StatusArgs};
use nextsync::config::config::Config;
use std::io;
@@ -17,7 +17,7 @@ fn indexed_expected(indexer: &Indexer, expected: Vec<&str>) {
for obj in expected {
assert!(objs
.iter()
.position(|e| { e.path == PathBuf::from(obj) })
.position(|e| { e.path == to_obj_path(&PathBuf::from(obj)) })
.is_some());
}
}

View File

@@ -1,8 +1,7 @@
use nextsync::config::config::Config;
use std::fs::OpenOptions;
use rand::{distributions::Alphanumeric, Rng};
use std::env;
use std::fs::{self, File};
use std::fs::{self, File, OpenOptions};
use std::io::{self, Write};
use std::path::PathBuf;
use std::process::{Command, Output};
@@ -136,11 +135,12 @@ impl ClientTest {
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 mut file = OpenOptions::new()
.write(true)
.create(true)
.append(true)
.open(nsignore_path)
.unwrap();
let _ = writeln!(file, "{rule}").unwrap();
}

View File

@@ -1,6 +1,7 @@
mod common;
use common::client::ClientTest;
use nextsync::store::object::Obj;
use nextsync::commands::status::{get_obj_changes, StatusArgs};
use nextsync::config::config::Config;
use std::io;
@@ -8,43 +9,30 @@ use std::path::PathBuf;
const DEFAULT_STATUS_ARG: StatusArgs = StatusArgs { nostyle: false };
fn compare_vect(vec1: Vec<Obj>, vec2: Vec<&str>, config: &Config) {
for obj in vec2 {
assert!(
vec1.iter()
.position(|e| {
e.get_env_relative_path(config.get_root_unsafe()) == PathBuf::from(obj)
})
.is_some(),
"{:?}",
vec1.iter()
.map(|e| { e.get_env_relative_path(config.get_root_unsafe()) })
.collect::<Vec<PathBuf>>()
);
}
}
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());
assert_eq!(res.not_staged.len(), not_staged.len());
for obj in staged {
assert!(
res.staged
.iter()
.position(|e| {
e.get_env_relative_path(config.get_root_unsafe()) == PathBuf::from(obj)
})
.is_some(),
"{:?}",
res.staged
.iter()
.map(|e| { e.get_env_relative_path(config.get_root_unsafe()) })
.collect::<Vec<PathBuf>>()
);
}
for obj in not_staged {
assert!(
res.not_staged
.iter()
.position(|e| {
e.get_env_relative_path(config.get_root_unsafe()) == PathBuf::from(obj)
})
.is_some(),
"{:?}",
res.not_staged
.iter()
.map(|e| { e.get_env_relative_path(config.get_root_unsafe()) })
.collect::<Vec<PathBuf>>()
);
}
compare_vect(res.staged, staged, &config);
compare_vect(res.not_staged, not_staged, &config);
}
#[test]